SoFunction
Updated on 2025-04-12

MooTools page scrolling floating layer intelligent positioning implementation code


var $smartFloat = function(elements) {
var position = function(element) {
var top = ().y, pos = ("position");
("scroll", function() {
var scrolls = ().y;
if (scrolls > top) {
if () {
({
position: "fixed",
top: 0
});
} else {
({
top: scrolls
});
}
}else {
({
position: "absolute",
top: top
});
}
});
};
if ($type(elements) === "array") {
return (function(items) {
position(items);
});
} else if ($type(elements) === "element") {
position(elements);
}
};

//Binding
$smartFloat($("float"));