Created
December 23, 2017 14:42
-
-
Save hellojinjie/ac849b9cf7982fc62d2d36ac6bdb0111 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
$.fn.smartFloat = function() { | |
var position = function(element) { | |
var top = element.position().top, pos = element.css("position"); | |
$(window).scroll(function() { | |
var scrolls = $(this).scrollTop(); | |
if (scrolls > top) { | |
if (window.XMLHttpRequest) { | |
element.css({ | |
position: "fixed", | |
top: 0 | |
}); | |
} else { | |
element.css({ | |
top: scrolls | |
}); | |
} | |
}else { | |
element.css({ | |
position: "absolute", | |
top: top | |
}); | |
} | |
}); | |
}; | |
return $(this).each(function() { | |
position($(this)); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment