国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jQuery實現(xiàn)自動滾動到頁面頂端的方法

2024-05-06 16:20:45
字體:
供稿:網(wǎng)友

這篇文章主要介紹了jQuery實現(xiàn)自動滾動到頁面頂端的方法,涉及jQuery針對頁面操作的相關(guān)技巧,需要的朋友可以參考下

本文實例講述了jQuery實現(xiàn)自動滾動到頁面頂端的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

 

 
  1. $(".scroll").click(function(event) 
  2. //prevent the default action for the click event 
  3. event.preventDefault(); 
  4. //get the full url - like mysitecom/index.htm#home 
  5. var full_url = this.href; 
  6. //split the url by # and get the anchor target  
  7. //name - home in mysitecom/index.htm#home 
  8. var parts = full_url.split("#"); 
  9. var trgt = parts[1]; 
  10. //get the top offset of the target anchor 
  11. var target_offset = $("#"+trgt).offset(); 
  12. var target_top = target_offset.top; 
  13. //goto that anchor by setting the body scroll top to anchor top 
  14. $('html, body').animate({scrollTop:target_top}, 500); 
  15. });? 

希望本文所述對大家的jQuery程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 丘北县| 嘉鱼县| 从江县| 玉溪市| 甘洛县| 普陀区| 广西| 黑龙江省| 观塘区| 霍州市| 会宁县| 太康县| 大方县| 万宁市| 天气| 温州市| 武川县| 怀来县| 女性| 东安县| 积石山| 宁明县| 松江区| 台中市| 青田县| 黄平县| 班戈县| 勃利县| 霍山县| 镇远县| 丹寨县| 康马县| 高州市| 旺苍县| 汕尾市| 凤山市| 三门县| 新蔡县| 湘乡市| 西充县| 红原县|