日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

返回顶部 js

發布時間:2024/1/17 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 返回顶部 js 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

返回頂部:

1.可以在網頁添加錨鏈接

2.利用js 可以實現動畫效果

<!DOCTYPE HTML> <html> <head><meta charset="gb2312"><title>goTop</title><style type="text/css">* {margin:0;padding:0;}#goTop {position:fixed;right:20px;bottom:40px;width:40px;height:32px;padding:8px 0 0;background-color:#666;border-radius:6px;cursor:pointer;}#goTop:hover {background-color:#333;}#goTop:hover .gotop1 {border-left:12px solid #333;border-right:12px solid #333;}#goTop .gotop1 {width:0;margin:0 auto;border-bottom:12px solid #FFF;border-left:12px solid #666;border-right:12px solid #666;}#goTop .gotop2 {width:10px;height:10px;margin:0 auto;background-color:#FFF;}</style> <!--[if IE 6]> <style> /*解決IE6下position:fixed;問題*/ #goTop{ _position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,0)||0)-(parseInt(this.currentStyle.marginBottom,0)||10)));/*使元素固定在瀏覽器的底部*/ } </style> <![endif]--> </head> <body><div title="返回頂部" id="goTop" style="display:none;"><div class="gotop1"></div><div class="gotop2"></div></div><div><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p></div><script type="text/javascript">function $getId(Id) {return document.getElementById(Id);} var goTop = $getId("goTop");window.onscroll = function () {if (document.documentElement.scrollTop + document.body.scrollTop > 0) {goTop.style.display = "";} else {goTop.style.display = "none";}}goTop.onclick = function () {var Timer = setInterval(GoTop, 10);function GoTop() {if (document.documentElement.scrollTop + document.body.scrollTop < 1) {clearInterval(Timer);} else {document.documentElement.scrollTop /= 1.1;document.body.scrollTop /= 1.1;}}} </script> </body> </html>

關于onscroll:

scroll事件是在window對象上發生,但表示的是頁面相應元素的變化,
在混雜模式下:可以通過<body>元素的scrollLeft/scrollTop監控這一變化,
在標準模式下大多瀏覽器通過<html>元素反應這一變化(safari仍基于body)

參考:藍色理想:http://bbs.blueidea.com/thread-2979799-1-1.html

轉載于:https://www.cnblogs.com/hdchangchang/archive/2012/12/19/3965393.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的返回顶部 js的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。