国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表

圖片精選

主站蜘蛛池模板: 拜城县| 青浦区| 炎陵县| 治多县| 鸡西市| 化德县| 祁连县| 门源| 临沂市| 工布江达县| 七台河市| 杭锦旗| 油尖旺区| 泗水县| 炉霍县| 都安| 威信县| 上栗县| 信宜市| 白河县| 莱州市| 岚皋县| 积石山| 元江| 阳春市| 广水市| 永平县| 雅江县| 阜城县| 洪洞县| 房产| 宁夏| 兴山县| 栖霞市| 革吉县| 夏津县| 赤水市| 当雄县| 皮山县| 灯塔市| 临沭县|