jQuery實現(xiàn)自動滾動到頁面頂端的方法
更新時間:2015年05月22日 15:18:13 作者:不吃皮蛋
這篇文章主要介紹了jQuery實現(xiàn)自動滾動到頁面頂端的方法,涉及jQuery針對頁面操作的相關技巧,需要的朋友可以參考下
本文實例講述了jQuery實現(xiàn)自動滾動到頁面頂端的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
$(".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程序設計有所幫助。
相關文章
jQuery EasyUI Pagination實現(xiàn)分頁的常用方法
這篇文章主要為大家詳細介紹了jQuery EasyUI Pagination實現(xiàn)分頁的常用方法,感興趣的朋友可以參考一下2016-05-05
zepto與jquery的區(qū)別及zepto的不同使用8條小結
這篇文章主要介紹了zepto與jquery的區(qū)別及zepto的不同使用8條小結 的相關資料,需要的朋友可以參考下2016-07-07
jQuery實現(xiàn)的頁面遮罩層功能示例【測試可用】
這篇文章主要介紹了jQuery實現(xiàn)的頁面遮罩層功能,結合完整實例形式詳細分析了jQuery遮罩層實現(xiàn)步驟與相關操作技巧,需要的朋友可以參考下2017-10-10
如何使用jquery修改css中帶有!important的樣式屬性
如何使用jquery修改css中帶有!important的樣式屬性?下面小編就為大家?guī)硪黄褂胘query修改css中帶有!important的樣式屬性方法。希望對大家有所幫助。一起跟隨小編過來看看吧2016-04-04

