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:函数时,它不再滚动,但某些打开/关闭功能停止执行。