-
-
Save xrman/b1800d915b7a635822354b46507f46c0 to your computer and use it in GitHub Desktop.
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
<!-- html --> | |
<div class="sticky_anchor"></div> | |
/* css */ | |
.sticky{ | |
position: fixed; | |
top: 0; | |
z-index: 2; | |
background: #fff; | |
width: 100%; | |
-webkit-animation: sticky .5s; | |
animation: sticky .5s; | |
} | |
@-webkit-keyframes sticky { | |
0% { | |
top: -100px; | |
opacity: 0; | |
} | |
100% { | |
top: 0; | |
opacity: 1 | |
} | |
} | |
@keyframes sticky { | |
0% { | |
top: -100px; | |
opacity: 0; | |
} | |
100% { | |
top: 0; | |
opacity: 1 | |
} | |
} | |
#sticky_anchor.active{ | |
height: 83px; | |
width: 100%; | |
-webkit-transition: .9s; | |
-o-transition: .9s; | |
transition: .9s; | |
} | |
//js | |
$(window).on('scroll',function(){ | |
if($(window).scrollTop()>10){ | |
$('.stick').addClass('sticky'); | |
$('#sticky_anchor').addClass('active'); | |
} | |
else{ | |
$('.stick').removeClass('sticky'); | |
$('#sticky_anchor').removeClass('active'); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment