jquery實現(xiàn)頁面常用的返回頂部效果
更新時間:2016年03月04日 10:05:01 投稿:lijiao
這篇文章主要為大家詳細介紹了jquery實現(xiàn)頁面常用的返回頂部效果代碼,感興趣的小伙伴們可以參考一下
本文實例為大家分享了jquery實現(xiàn)返回頂部效果的全部代碼,供大家參考,具體內(nèi)容如下
效果圖:
實現(xiàn)代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>返回頂部</title> <style type="text/css"> *{ margin: 0; padding: 0; } .wrap{ height: 2000px; } .gotop{ display: block; width: 32px; height: 32px; background-color: red; text-align: center; text-decoration: none; font-size: 14px; font-weight: bold; color: white; line-height: 32px; position: fixed; right:50px; bottom:50px; opacity: 0; /*top: 500px;*/ } </style> </head> <body> <div class="wrap"> <a href="###" class="gotop">TOP</a> </div> <script type="text/javascript" src="jquery-1.11.3.min.js"></script> <script type="text/javascript"> $(function(){ // 當滾動條滾動大于200時出現(xiàn),未大于,消失 $(window).scroll(function(){ if($(document).scrollTop()<200){ // alert("kk"); $(".gotop").stop().animate({ opacity: 0 },1000) } else{ $(".gotop").show().stop().animate({ opacity: 1 },1000) } }) // 返回頂部 $(".gotop").on("click",function(){ $("html body").animate({ scrollTop:0 },1000) }) }) </script> </body> </html>
希望本文所述對大家學習javascript程序設計有所幫助。
相關文章
得到jQuery detach()后節(jié)點中的某個值實現(xiàn)代碼
需要jQuery -detach 后的dom 結(jié)構或某個值,如何獲取到呢?一直困惑著我們,不過本文將為大家解開疑惑,感興趣的朋友可以了解下,或許本文對你有所幫助2013-02-02Jquery 動態(tài)添加元素并添加點擊事件實現(xiàn)過程解析
這篇文章主要介紹了Jquery 動態(tài)添加元素并添加點擊事件實現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-10-10jQuery zTree搜索-關鍵字查詢 遞歸無限層功能實現(xiàn)代碼
這篇文章主要介紹了zTree搜索功能 -- 關鍵字查詢 -- 遞歸無限層的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2018-01-01JQuery實現(xiàn)動態(tài)適時改變字體顏色的方法
這篇文章主要介紹了JQuery實現(xiàn)動態(tài)適時改變字體顏色的方法,實例分析了jQuery操作鼠標事件及顏色的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03