Copy Code code as follows:
<script type= "Text/javascript" >
(function ($) {
var Ele_fix = $ ("#div_right"); Floating window
var _main = $ (". Main"); Floating area
var ele_offset_top = Ele_fix.offset (). Top; Floating area Height
$ (window). Scroll (function () {
var scro_top = $ (this). ScrollTop (); Current height
var fix_foot_pos = parseint (Ele_fix.height ()) +parseint (scro_top)-10; The bottom of the floating box to the top height
var mainpos = parseint (_main.offset (). Top) +parseint (_main.height ());
if (scro_top <= ele_offset_top&&fix_foot_pos<mainpos) {
Ele_fix.css ({position: "Static", Top:-10});
}else if (scro_top>ele_offset_top&&fix_foot_pos<mainpos) {
Ele_fix.css ({position: "fixed", Top:-10});
}else if (scro_top>ele_offset_top&&fix_foot_pos>mainpos) {
var posi = mainpos-fix_foot_pos-10;
Ele_fix.css ({position: "fixed", Top:posi});
}
});
/*
Programme II
$ (window). Bind ("scroll", function () {
var temp = ' 1165 ';
Judgment roll Down
if ($ (document). ScrollTop () > Temp) {//If greater than this height, top
Flag = false;
$ (' #div_right '). css ({' position ': ' fixed ', ' top ': ' -10px ', ' margin-top ': ' 0px '});
}
if ($ (document). ScrollTop () <= temp) {//if less than this height, restore the original state
Flag = true;
$ (' #div_right '). CSS (' position ', ');
}
});
*/
}) (JQuery);
</script>