0
我創建了一個jQuery對話框,可以從許多不同的按鈕打開和關閉,一切工作正常,除非我關閉對話框,瀏覽器滾動到頂部。我已經嘗試了許多在線的建議,但似乎沒有任何功能在阻止滾動的同時保持工作。jQuery對話框關閉滾動瀏覽器頂部
我創建像這樣的對話:
function create_hint_widget(hint_text) {
if ($("#hint_dialog").hasClass("ui-dialog-content"))
{
$("#hint_dialog").dialog("open");
$("#hint_dialog").html(hint_text);
}
else
{
return $("<div id='hint_dialog' title='Help'>" + hint_text + "</div>")
.dialog({
resizable: true,
height: 200,
width: 300,
modal: false,
position: ['right', 180],
close: function(ev, ui)
{
$("#hint_dialog").dialog("close");
},
});
}
}
這是Rails代碼來創建鏈接調用對話框:
<%= link_to image_tag("hint_link.jpeg", :size=>"13x13"),
'javascript:;', :onclick => 'create_hint_widget("Enter a name for your template. Each template must have a unique name.");
return false;' %>
我使用的開/關的因爲我希望它保持其立場。 event.stopPropagation();不停止scroll和event.preventDefault();打破/關閉功能。可能最重要的是,當我刪除我的close:函數時,它不再滾動,但某些打開/關閉功能停止執行。