Created
June 19, 2013 20:20
-
-
Save chadclark/5817682 to your computer and use it in GitHub Desktop.
Parallaxin'. Derived from http://net.tutsplus.com/tutorials/html-css-techniques/simple-parallax-scrolling-technique/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section data-type="background" data-speed="10"> | |
</section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section { | |
background: url(path/to/background) 0 0 repeat fixed; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
// $$$$$$$\ $$\ $$\ $$\ $$\ | |
// $$ __$$\ $$ |$$ | \__| $ | | |
// $$ | $$ |$$$$$$\ $$$$$$\ $$$$$$\ $$ |$$ | $$$$$$\ $$\ $$\ $$\ $$$$$$$\\_/ | |
// $$$$$$$ |\____$$\ $$ __$$\ \____$$\ $$ |$$ | \____$$\ \$$\ $$ |$$ |$$ __$$\ | |
// $$ ____/ $$$$$$$ |$$ | \__|$$$$$$$ |$$ |$$ | $$$$$$$ | \$$$$ / $$ |$$ | $$ | | |
// $$ | $$ __$$ |$$ | $$ __$$ |$$ |$$ |$$ __$$ | $$ $$< $$ |$$ | $$ | | |
// $$ | \$$$$$$$ |$$ | \$$$$$$$ |$$ |$$ |\$$$$$$$ |$$ /\$$\ $$ |$$ | $$ | | |
// \__| \_______|\__| \_______|\__|\__| \_______|\__/ \__|\__|\__| \__| | |
// | |
// | |
// | |
var $window = $(window); | |
$('section[data-type="background"]').each(function(){ | |
var $bgobj = $(this); // assigning the object | |
$(window).scroll(function() { | |
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 }); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment