Js-dom: Basic Real---Click Back to Top

Source: Internet
Author: User

CSS Section

<style type= "Text/css" >
body{
height:3000px;
}
#div1 {
height:100px;
width:100px;
Background-color: #ccc;
position:fixed;
right:0;
bottom:0;
}
</style>

HTML section

<body>
<div id= "Div1" ></div>
UL>LI{$}*50--->tab
</body>

Js-dom part

<script type= "Text/javascript" src= "Tween.js" ></script>

<script>

Window.onload=function () {

var Odiv=document.getelementbyid ("Div1");

function Move () {

if (Window.navigator.uesrAgent.indexOf ("MSIE 6")!=-1) {

var bodyscrolltop=document.documentelement.scrolltop;

var scrollbottom=document.documentelement.clientheight-odiv.offsetheight+bodyscrolltop;

odiv.style.position= "Absolute";

odiv.style.top=scrollbottom+ "px";

}

}

Move ();

  

Window.onscroll=window.onresize=function () {

Move ();

}

var timer=null;

Odiv.onclick=function () {

var start=document.documentelement.scrolltop| | Document.body.scrollTop;

var end=0;

var Change=end-start;

var t=0;

var endt=20;

Clearinterval (timer);

Timer=setinterval (function () {

t++;

if (T==endt) {

Clearinterval (timer);

}

Document.body.scrolltop=tween.bounce.easeout (T,start,change,endt);

Document.documentelement.scrolltop=tween.bounce.easeout (T,start,change,endt);

},30);

}

}

</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.