I have been told to start using Classes and Namespacing in my jQuery code and for a new app we are building we will be making the code very simple and slick. For example the following code is used on out login page to load all the content before fading it in:
// Hide the content and fadein the spinner
jQuery(document).ready(function()
{
$('#hide').hide();
$('body').append('<div id="loading">loading...</div>');
$("#loading").hide();
setTimeout($('#loading').fadeIn(), 200);
});
// When all content has loaded, fadeout the spinner and THEN fadein the content
jQuery(window).load(function ()
{
$("#loading").fadeOut("slow", function ()
{
$("#loading").remove();
clearInterval(loadingAnim);
$("#hide").fadeIn("slow");
});
});
var lastx = 0;
var loadingAnim = setInterval(function () { UpdateSpinner("#loading", 42, 504); }, 42);
function UpdateSpinner(target, step, width)
{
$(target).css("background-position", "0 " + lastx + "px");
lastx = (lastx - step) % width;
}
How could I make this more simple using Name spacing and classes?
Example of where I have seen this used: http://static.neow.in/js/pegasus/mainpage.js
Thanks