-
-
Save jsakhil/2c77dfd51482a566de1465ba1fa649ef to your computer and use it in GitHub Desktop.
Simple parallax background scrolling with jQuery
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
$(function() { | |
var $el = $('.parallax-background'); | |
$(window).on('scroll', function () { | |
var scroll = $(document).scrollTop(); | |
$el.css({ | |
'background-position':'50% '+(-.4*scroll)+'px' | |
}); | |
}); | |
}); |
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
.parallax-background { | |
background-image: url('http://placekitten.com/1000/1000'); | |
background-position: 50% 0; | |
background-repeat: no-repeat; | |
-webkit-background-size: cover; | |
background-size: cover; | |
-moz-transform: translate3d(0,0,0); | |
-webkit-transform: translate3d(0,0,0); | |
transform: translate3d(0,0,0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment