我試圖在某些頁面中使用jQuery的頁面滾動,并且可以成功地進(jìn)行平滑的頁面滾動。我現(xiàn)在唯一的問題是嘗試從其他頁面執(zhí)行此操作。我的意思是,如果我單擊頁面中的鏈接,它將加載新頁面,然后滾動到特定的div元素。這是我用來在頁面內(nèi)滾動的代碼: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;});我希望這個主意很清楚。謝謝非常重要的注意:我上面發(fā)布的這段代碼在同一頁面內(nèi)也很好用,但是我要單擊的是單擊一個頁面上的鏈接,然后轉(zhuǎn)到另一頁面,然后滾動到目標(biāo)。我希望現(xiàn)在已經(jīng)清楚了。謝謝
- 3 回答
- 0 關(guān)注
- 440 瀏覽
添加回答
舉報
0/150
提交
取消