国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 望城县| 长治市| 正镶白旗| 绥化市| 兰溪市| 彰化县| 济阳县| 肥城市| 芷江| 南漳县| 涟水县| 石棉县| 辛集市| 云安县| 蒲城县| 乌苏市| 南郑县| 砚山县| 夏邑县| 且末县| 新乡县| 高密市| 阳曲县| 宁陕县| 光山县| 游戏| 水城县| 宿迁市| 定远县| 临海市| 泰宁县| 曲水县| 上虞市| 依安县| 隆回县| 永康市| 临洮县| 西林县| 黄冈市| 花莲市| 大余县|