$(function() { //cache the window object var $window = $(window); //Parallax background effect $('section[data-type="background"]').each(function() { var $bgobj = $(this); // assiging the object $(window).scroll(function() { //scroll the background at var speed //the ypos is a negative value because we're scrolling it up var yPos= -($window.scrollTop() / $bgobj.data('speed')); //put together our final background position var coords = '50% '+ yPos + 'px' ; //move the background $bgobj.css({backgroundPosition: coords}); });// end window scroll }); }); var amountScrolled = 300; $(window).scroll(function() { if ( $(window).scrollTop() > amountScrolled ) { $('a.back-to-top').fadeIn('slow'); } else { $('a.back-to-top').fadeOut('slow'); } }); $('a.back-to-top').click(function() { $('html, body').animate({ scrollTop: 0 }, 700); return false; });