標籤:
實現的效果也就是,當有捲軸是,捲軸未動或與頂部距離小於多少像素是,返回頂部按鈕處於隱藏狀態,當捲軸與頂部距離大於一定像素時,返回頂部按鈕出現,實現點擊‘返回按鈕’後,從當前位置回到等不位置。要先引用jquery.min.js
<script src="__PUBLIC__/js/jquery-2.1.4.min.js"></script>
html:
<div id="back-to-top" style="display:none">返<br />回<br />頂<br />部</div>
css:
#back-to-top{ width: 25px;position:fixed;bottom:20px;right:20px;border:solid 1px #ccc;cursor:pointer;text-align: center;color: red; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0))); }
js:
jQuery(function ($) { //當捲軸的位置處於距頂部20像素以下時,跳轉連結出現,否則消失 $(window).scroll(function(){ if (jQuery(window).scrollTop()>20){ jQuery("#back-to-top").fadeIn(1000); } else { jQuery("#back-to-top").fadeOut(1000); } }); //當點擊跳轉連結後,回到頁面頂部位置 jQuery("#back-to-top").click(function(){ jQuery(‘body,html‘).animate({scrollTop:0},1000); return false; }); });
jquery右下角返回頂部