1. 程式人生 > >jquery實現跳轉到頁面指定位置

jquery實現跳轉到頁面指定位置

方法1:

var t = $('#accountListDiv').offset().top;//  獲取需要跳轉到標籤的top值
$(window).scrollTop(t);// 跳轉到指定位置

方法2:

var t = $('#accountListDiv').offset().top;//  獲取需要跳轉到標籤的top值
$("html,body").animate({ scrollTop: t}, 500); // 動態跳轉到指定位置(數值越大滾動速度越慢)

方法3:

$("#showPagesA").attr("href","#accountListDiv");// #showPagesA是一個a標籤  #accountListDiv

是要跳到位置的id值
document.getElementById("showPagesA").click();// a標籤實現點選然後跳轉到指定位置