Jquery is compatible with ie6 after scrolling to the navigation bar and floating stop on the top of the page

Source: Internet
Author: User

This article will introduce you in detail a jquery code compatible with the ie6 instance on the top of the suspended page after scrolling to the navigation bar. For more information, see.

Jquery Implementation Method

The Code is as follows: Copy code

<Script type = "text/javascript">
$ (Function (){

If ($. browser. msie & ($. browser. version = "6.0 ")&&! $. Support. style ){
Var handler, sTop, dTop;
DTop = $ ("# fixedNav"). offset (). top
$ (Window). bind ('scroll ', function (){
Window. clearTimeout (handler );
Handler = window. setTimeout (function (){
STop = $ (document). scrollTop ();
STop> dTop? $ ("# FixedNav" ).css ("top", sTop-dTop): $ ("# fixedNav" ).css ("top", 0 );
$ ("# FixedNav" ).css ({"position": "relative", "z-index": "1200 "});
}, 60 );
});
} Else {

Var topMain = $ ("# fixedNav"). offset (). top
$ (Window). scroll (function (){
If ($ (window). scrollTop ()> topMain ){
$ ("# FixedNav"). addClass ("nav_scroll ");
} Else {
$ ("# FixedNav"). removeClass ("nav_scroll ");
}
});

}
});
</Script>

Css code

The Code is as follows: Copy code

. Nav_scroll {position: fixed; top: 0; left: 0; z-index: 1200; width: 100% ;}

Html

The Code is as follows: Copy code

<Div id = fixedNav> jquery implements ie6 compatibility at the top of the suspended page after scrolling to the navigation bar, where content is placed </div>


A section of js Code is provided below

 

The Code is as follows: Copy code

<Script type = "text/javascript">
Function htmlScroll ()
{
Var top = document. body. scrollTop | document.doc umentElement. scrollTop;
If (elFix. data_top <top)
{
ElFix. style. position = 'fixed ';
ElFix. style. top = 0;
ElFix. style. left = elFix. data_left;
}
Else
{
ElFix. style. position = 'static ';
}
}

Function htmlPosition (obj)
{
Var o = obj;
Var t = o. offsetTop;
Var l = o. offsetLeft;
While (o = o. offsetParent)
{
T + = o. offsetTop;
L + = o. offsetLeft;
}
Obj. data_top = t;
Obj. data_left = l;
}

Var oldHtmlWidth = document.doc umentElement. offsetWidth;
Window. onresize = function (){
Var newHtmlWidth = document.doc umentElement. offsetWidth;
If (oldHtmlWidth = newHtmlWidth)
{
Return;
}
OldHtmlWidth = newHtmlWidth;
ElFix. style. position = 'static ';
HtmlPosition (elFix );
HtmlScroll ();
}
Window. onscroll = htmlScroll;

Var elFix = document. getElementById ('fixedright ');
HtmlPosition (elFix );

</Script>

Related Article

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.