一个强悍的网页特效,点击链接滚动到相应的位置,带返回顶部功能,网站中常用于点击问题题目滚动到答案位置效果。
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> #container{ text-align: left; background-color: #faf7ec; width: 500px; margin: 20px auto 0 auto; padding: 0; font-family:Arial, Helvetica, sans-serif; font-size:12px; } #block0, #block1, #block2, #block3, #block4, #block5 { border-top: solid 1px #785a3c; margin: 0; padding: 10px; } .active { background-color: #fff; } .visited { background-color: #ede7da; } #block0, #block0.active, #block0.visited { text-align: center; background-color: #a0dcf8; border-top: none; border-bottom: solid 4px #785a3c; } </style> <script> var ScrollWin = { w3c : document.getElementById, iex : document.all, scrollLoop : false, scrollInterval : null, // setInterval id currentBlock : null, // object reference getWindowHeight : function(){ if(this.iex) return (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight; else return window.innerHeight; }, getScrollLeft : function(){ if(this.iex) return (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft; else return window.pageXOffset; }, getScrollTop : function(){ if(this.iex) return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop; else return window.pageYOffset; }, getElementYpos : function(el){ var y = 0; while(el.offsetParent){ y += el.offsetTop el = el.offsetParent; }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) return y; }, scroll : function(num){ if(!this.w3c){ location.href = "#"+this.anchorName+num; return; } if(this.scrollLoop){ clearInterval(this.scrollInterval); this.scrollLoop = false; this.scrollInterval = null; }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) if(this.currentBlock != null) this.currentBlock.className = this.offClassName; this.currentBlock = document.getElementById(this.blockName+num); this.currentBlock.className = this.onClassName; var doc = document.getElementById(this.containerName); var documentHeight = this.getElementYpos(doc) + doc.offsetHeight; var windowHeight = this.getWindowHeight(); var ypos = this.getElementYpos(this.currentBlock); if(ypos > documentHeight - windowHeight) ypos = documentHeight - windowHeight; this.scrollTo(0,ypos); }, scrollTo : function(x,y){ if(this.scrollLoop){ var left = this.getScrollLeft(); var top = this.getScrollTop(); if(Math.abs(left-x) <= 1 && Math.abs(top-y) <= 1){ window.scrollTo(x,y); clearInterval(this.scrollInterval); this.scrollLoop = false; this.scrollInterval = null; }else{ window.scrollTo(left+(x-left)/10, top+(y-top)/10); }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) }else{ this.scrollInterval = setInterval("ScrollWin.scrollTo("+x+","+y+")",20); this.scrollLoop = true; } }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) }; ScrollWin.containerName = "container"; ScrollWin.anchorName = "anchor"; ScrollWin.blockName = "block"; ScrollWin.onClassName = "active"; ScrollWin.offClassName = "visited"; </script> </head> <body> <a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr> <!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。--> <script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script> <!--<script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script>--> <div align="center"> <div id="container"> <a name="anchor0"></a> <div id="block0"> <a href="javascript:ScrollWin.scroll('1')">链接 1</a> | <a href="javascript:ScrollWin.scroll('2')">链接 2</a> | <a href="javascript:ScrollWin.scroll('3')">链接 3</a> | <a href="javascript:ScrollWin.scroll('4')">链接 4</a> | <a href="javascript:ScrollWin.scroll('5')">链接 5</a> </div> <a name="anchor1"></a> <div id="block1"> <h3><a href="#" onclick="javascript:ScrollWin.scroll('0'); return false;">顶部</a> 链接 1</h3> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> </div> <a name="anchor2"></a> <div id="block2"> <h3><a href="#" onclick="javascript:ScrollWin.scroll('0'); return false;">顶部</a> 链接 2</h3> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> </div> <a name="anchor3"></a> <div id="block3"> <h3><a href="#" onclick="javascript:ScrollWin.scroll('0'); return false;">顶部</a> 链接 3</h3> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> </div> <a name="anchor4"></a> <div id="block4"> <h3><a href="#" onclick="javascript:ScrollWin.scroll('0'); return false;">顶部</a> 链接 4</h3> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> </div> <a name="anchor5"></a> <div id="block5"> <h3><a href="#" onclick="javascript:ScrollWin.scroll('0'); return false;">顶部</a> 链接 5</h3> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> <p>内容</p> </div> </div> </div> </body>
本文来自武鸣人网站,转载请注明出处