2012-09-19 19 views
0

#標籤會導致頁面滾動到我已經包含在我的fancybox腳本以下腳本頂部

beforeShow: function() { 
    var id = this.element.attr("id") 
    if (id) { 
     window.location.hash = id; 
    } 
},     
beforeClose: function() { 
    window.location.hash = ""; 
} 

基本上,如果我打開使用的fancybox的圖像時,URL將變爲/#圖像當的fancybox窗口關閉後,網址將更改爲/#。但是,當發生這種情況時,頁面會滾動回頂部。有什麼辦法可以避免這種情況?

+1

退房這個問題:http://stackoverflow.com/questions/645202/can-i-update-window-location-hash-without-having-the -web-page-scroll – LeonardChallis

回答

1

您可以存儲前值:

var scroll = $(window).scrollTop(); 
// change hash to # 
$(window).scrollTop(scroll); 
+0

謝謝。但是,是否有可能不滾動到圖像的開頭,而是加載上一個滾動位置? – coldpumpkin

相關問題