Home > Web Front-end > JS Tutorial > MooTools page scrolling floating layer intelligent positioning implementation code_Mootools

MooTools page scrolling floating layer intelligent positioning implementation code_Mootools

WBOY
Release: 2016-05-16 18:03:06
Original
925 people have browsed it

HTML code:

Copy code The code is as follows:


I am a shy floating layer...


JS code:
Copy code The code is as follows:

var $smartFloat = function(elements) {
var position = function(element) {
var top = element.getPosition().y, pos = element.getStyle("position");
window.addEvent("scroll", function() {
var scrolls = this.getScroll(). y;
if (scrolls > top) {
if (window.XMLHttpRequest) {
element.setStyles({
position: "fixed",
top: 0
} );
} else {
element.setStyles({
top: scrolls
});
}
}else {
element.setStyles({
position : "absolute",
top: top
});
}
});
};
if ($type(elements) === "array") {
return elements.each(function(items) {
position(items);
});
} else if ($type(elements) === "element") {
position(elements);
}
};

//Binding
$smartFloat($("float"));
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template