The intelligent positioning implementation code of the floating layer on the page of the MooTools page. For more information, see. HTML code:
The Code is as follows:
I am a shy floating layer...
JS 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 );
}
};
// Bind
$ SmartFloat ($ ("float "));