Home >Web Front-end >JS Tutorial >jQuery page scrolling floating layer intelligent positioning example code_jquery

jQuery page scrolling floating layer intelligent positioning example code_jquery

WBOY
WBOYOriginal
2016-05-16 18:03:09805browse

HTML code:

Copy code The code is as follows:


I am a shy floating layer...


JS code:
Copy code The code is as follows:

$.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));
});
};
//Binding
$("#float").smartFloat();
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn