Click here to Skip to main content
15,892,643 members
Articles / Web Development / HTML5

HTML5, JavaScript, Knockout, JQuery, Guide for Recovering Silverlight/WPF/C# Addicts. Part 2 - Solar System Animation built with SVG, Knockout and MVVM Pattern.

Rate me:
Please Sign up or sign in to vote.
4.98/5 (32 votes)
26 Sep 2012CPOL16 min read 80.6K   1.4K   70  
Creating Solar System animation in HTML5/JavaScript
/// <reference path="knockout-2.1.0.debug.js" />

// setting up the namespace
var solarSystemBodyNmspace = solarSystemBodyNmspace || {};

// set the view models to an empty object
solarSystemBodyNmspace.solarSystemBodyVM = {};

// let us have the solar system object contain only name and details  
// as well as the computed fullDescription field, for the sake of simplicity
solarSystemBodyNmspace.solarSystemBodyVM = {
    name : ko.observable("Earth"),
    details: ko.observable("the planet we live on") 
};

// computed observables should be defined outside
// of JSON object definition in order for 
// 'this' reference to be correct.
// first argument to the ko.computed function is the function 
// for calculating the computed observable property.
// Second argument passes an object that becomes "this" pointer inside the function.
// This is needed, since the "this" pointer in JavaScript is much more fluid than
// "this" pointer or reference in C++ or C#/Java.
solarSystemBodyNmspace.solarSystemBodyVM.fullDescription = ko.computed(function () {
    return this.name() + ": " + this.details();
}, solarSystemBodyNmspace.solarSystemBodyVM);

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect AWebPros
United States United States
I am a software architect and a developer with great passion for new engineering solutions and finding and applying design patterns.

I am passionate about learning new ways of building software and sharing my knowledge with others.

I worked with many various languages including C#, Java and C++.

I fell in love with WPF (and later Silverlight) at first sight. After Microsoft killed Silverlight, I was distraught until I found Avalonia - a great multiplatform package for building UI on Windows, Linux, Mac as well as within browsers (using WASM) and for mobile platforms.

I have my Ph.D. from RPI.

here is my linkedin profile

Comments and Discussions