Last active
February 22, 2018 09:24
-
-
Save mrkkr/a2b1ebfb17514b3a502e0eeb28d9452f to your computer and use it in GitHub Desktop.
Wybrany element staje sie fixed po scrollowaniu do tego elementu #js #css
This file contains 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
var fixmeTop = $('.element-fixed'); | |
if (fixmeTop.length) { | |
var fixmeTopLength = fixmeTop.offset().top; // get initial position of the element | |
} | |
$(window).scroll(function() { // assign scroll event listener | |
var currentScroll = $(window).scrollTop(); // get current position | |
if (currentScroll >= fixmeTopLength) { // apply position: fixed if you | |
$('.element-fixed').css({ // scroll to that element or below it | |
'position': 'fixed', | |
'top': '137px', | |
'z-index':'999', | |
'width': '100%', | |
'left': '0', | |
}); | |
} else { // apply position: static | |
$('.element-fixed').css({ // if you scroll above it | |
'position': 'static' | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment