Last active
October 28, 2017 00:10
-
-
Save Sanix-Darker/2cadbf16319f863e0dd3afead8f28528 to your computer and use it in GitHub Desktop.
[JS]Fixed a div when scroll
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
$.fn.followTo = function (pos) { | |
var $this = this, | |
$window = $(window); | |
$window.scroll(function (e) { | |
if ($window.scrollTop() > pos) { | |
$this.css({ | |
position: 'fixed', | |
top: 0 | |
}); | |
} else { | |
$this.removeAttr('style'); | |
} | |
}); | |
}; | |
// Calling the function | |
$('#div').followTo(50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As simple as it