浮动div,回到顶部
生活随笔
收集整理的這篇文章主要介紹了
浮动div,回到顶部
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
<div style="height: 5000px">這是頂部</div>
<div id="FloatDIV" style="position: absolute;top: 0px; z-index:9999; background: #fff000;cursor: pointer"onclick="window.scrollTo(0,0);">回到頂部
</div><script type="text/javascript"> var MarginLeft = 10; //浮動層離瀏覽器右側(cè)的距離var MarginTop = document.body.clientHeight - 80; //浮動層離瀏覽器頂部的距離(瀏覽器高度-div高度)var Width = 25; //浮動層寬度var Heigth= 80; //浮動層高度//設(shè)置浮動層寬、高function Set(){document.getElementById("FloatDIV").style.width = Width + 'px';document.getElementById("FloatDIV").style.height = Heigth + 'px';}//實時設(shè)置浮動層的位置function Move(){var b_top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;var b_width= document.body.clientWidth;document.getElementById("FloatDIV").style.top = b_top + MarginTop + 'px';document.getElementById("FloatDIV").style.left = b_width - Width - MarginLeft + 'px';setTimeout("Move();",100);}Set();Move();</script>
?
回到頂部轉(zhuǎn)載于:https://www.cnblogs.com/ljmin/archive/2012/07/30/2616091.html
總結(jié)
以上是生活随笔為你收集整理的浮动div,回到顶部的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 穷举算法实例
- 下一篇: Codeforces 746 G. Ne