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

首頁 > 編程 > JavaScript > 正文

jQuery實現自動滾動到頁面頂端的方法

2019-11-20 12:25:47
字體:
來源:轉載
供稿:網友

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

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

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巴里| 米易县| 吉安县| 大庆市| 绥中县| 安顺市| 临猗县| 秦皇岛市| 濮阳市| 荥经县| 东城区| 昭苏县| 富顺县| 怀安县| 潮州市| 友谊县| 上杭县| 阳春市| 正蓝旗| 嵊州市| 精河县| 固原市| 汝州市| 晋江市| 石阡县| 琼海市| 扎赉特旗| 扎兰屯市| 大连市| 博客| 衡阳县| 凉城县| 嵩明县| 巨鹿县| 弋阳县| 方城县| 永善县| 名山县| 安龙县| 桐乡市| 涟源市|