The implementation of JS fixed suspension effect code _JAVASCRIPT skills

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.