Return the JS effect on the top (ie7, Firefox, google, and google all pass the test)

Source: Internet
Author: User

Previously, it was quite helpful to find the JS effect at the top of a website. The only difference was that Google couldn't support it. After modification, it can now be tested. Now I have posted the code for your reference. I hope this will help you.

 


<Script type = "text/javascript">


Var Sys = {};
Var ua = navigator. userAgent. toLowerCase ();
Var s;
(S = ua. match (/msie ([\ d.] + )/))? Sys. ie = s [1]:
(S = ua. match (/firefox \/([\ d.] + )/))? Sys. firefox = s [1]:
(S = ua. match (/chrome \/([\ d.] + )/))? Sys. chrome = s [1]:
(S = ua. match (/opera. ([\ d.] + )/))? Sys. opera = s [1]:
(S = ua. match (/version \/([\ d.] +). * safari /))? Sys. safari = s [1]: 0;

Function goTopEx (){
Var obj = document. getElementById ("goTopBtn ");
Var scrollTop = window. pageYOffset | document.doc umentElement. scrollTop | document. body. scrollTop | 0
Function getScrollTop (){
Var xsun = document.doc umentElement. scrollTop;
If (Sys. chrome ){
Xsun = document. body. scrollTop;
}
Return xsun;
}
Function setScrollTop (value ){
If (Sys. chrome ){
Document. body. scrollTop = value;
}
Else {
Document.doc umentElement. scrollTop = value;
}
}
Window. onscroll = function () {getScrollTop ()> 0? Obj. style. display = "": obj. style. display = "none ";}
Obj. onclick = function (){
Var goTop = setInterval (scrollMove, 10 );
Function scrollMove (){
SetScrollTop (getScrollTop ()/1.1 );
If (getScrollTop () <1) clearInterval (goTop );
}
}
}


</Script>

The header-defined var Sys ={}; is used to determine the browser, which is very useful.

 


Page call method:

<DIV style = "DISPLAY: none" id = goTopBtn> </DIV>
<SCRIPT type = text/javascript> goTopEx (); </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.