我試圖在某些頁面中使用jQuery的頁面滾動,并且可以成功地進行平滑的頁面滾動。我現在唯一的問題是嘗試從其他頁面執行此操作。我的意思是,如果我單擊頁面中的鏈接,它將加載新頁面,然后滾動到特定的div元素。這是我用來在頁面內滾動的代碼:var jump=function(e){ //prevent the "normal" behaviour which would be a "hard" jump e.preventDefault(); //Get the target var target = $(this).attr("href"); //perform animated scrolling $('html,body').animate( { //get top-position of target-element and set it as scroll target scrollTop: $(target).offset().top //scrolldelay: 2 seconds },2000,function() { //attach the hash (#jumptarget) to the pageurl location.hash = target; });}$(document).ready(function(){ $('a[href*=#]').bind("click", jump); return false;});我希望這個主意很清楚。謝謝非常重要的注意:我上面發布的這段代碼在同一頁面內也很好用,但是我要單擊的是單擊一個頁面上的鏈接,然后轉到另一頁面,然后滾動到目標。我希望現在已經清楚了。謝謝
- 3 回答
- 0 關注
- 455 瀏覽
添加回答
舉報
0/150
提交
取消
