Skip to content

Instantly share code, notes, and snippets.

@jimmy89Li
Created March 29, 2017 09:17
Show Gist options
  • Save jimmy89Li/021a60241559132b5eb6d73ee5933f72 to your computer and use it in GitHub Desktop.
Save jimmy89Li/021a60241559132b5eb6d73ee5933f72 to your computer and use it in GitHub Desktop.
Parallax
<!--HTML-->
<div class="header">
<div class="headerBg"></div>
</div>
<!--STYLE-->
<style>
.headerBg {
background-image: url(../img/headerBg.png);
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
display: block;
background-size: cover;
background-position: center;
transition: 0s linear;
transition-property: background-position;
}
</style>
<!--JS-->
<script>
//Scrollhandling
$(window).scroll(function(e){
//Parallax
var scrolled = $(window).scrollTop();
$('.headerBg').css('top',-(scrolled*0.5)+'px');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment