本文實例講述了jquery實現的動態回到頂部特效代碼。分享給大家供大家參考,具體如下:
這款jquery動態回到頂部特效,不是一下子就回到了網頁頂部,而是帶點緩沖的效果,有動畫效果,使用了jQuery插件,這是個非常常用的網頁特效,希望大家喜歡哦。
運行效果截圖如下:
在線演示地址如下:
http://demo.VeVB.COm/js/2015/jquery-back-top-dh-style-codes/
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>jquery動態回到頂部特效</title></head><body><style>#goTopBtn {position: fixed;line-height:36px;width:36px;bottom:35px;height:36px;cursor:pointer;display:none;background:url(images/back_to_top_white.gif);}</style><br/><p style="text-align:center;font-family:Georgia, 'Times New Roman', Times, serif;font-size:24px;font-weight:bold;">***,how are you。<br/>Just do what you want do!!!</p><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><div id="goTopBtn"></div><script type="text/javascript" src="jquery1.3.2.js"></script><script type="text/javascript"> $(window).scroll(function(){ var sc=$(window).scrollTop(); var rwidth=$(window).width() if(sc>0){ $("#goTopBtn").css("display","block"); $("#goTopBtn").css("left",(rwidth-36)+"px") }else{ $("#goTopBtn").css("display","none"); } }) $("#goTopBtn").click(function(){ var sc=$(window).scrollTop(); $('body,html').animate({scrollTop:0},500); })</script></body></html>
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答