Copy codeThe Code is 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 of the 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 ){
Varposi = mainpos-fix_foot_pos-10;
Ele_fix.css ({position: "fixed", top: posi });
}
});
/*
// Solution 2
$ (Window). bind ("scroll", function (){
Var temp = '20140901 ';
// Judge to roll down
If ($ (document). scrollTop ()> temp) {// if it is greater than this height, it is set to the top
Flag = false;
Detail ('includiv_right'detail .css ({'position': 'fixed', 'top': '-10px', 'margin-top': '0px '});
}
If ($ (document). scrollTop () <= temp) {// if the height is smaller than this value, the original state is restored.
Flag = true;
Certificate ('audio div_right'audio .css ('position ','');
}
});
*/
}) (JQuery );
</Script>