简体   繁体   English

设置div位置固定而页面不跳

[英]Set div position fixed without page jumping up

I have a modal dialog (jquery.dialog) that opens up when a user clicks on a link. 我有一个模式对话框(jquery.dialog),当用户单击链接时会打开。 I want to hide the scroll bar on the page behind the dialog, so user will not be able to use it. 我想在对话框后面隐藏页面上的滚动条,因此用户将无法使用它。 This works perfectly fine with the overflow:hidden except older IE browsers that mess the entire page up when doing that. 这与overflow:hidden完美配合,但较旧的IE浏览器会导致整个页面混乱,这是隐藏的。

So I came up with this to make it work in the IE: I created a div that was covering the entire content of the page and set it to position:relative and width/height:100%. 因此,我想出了一个办法使其在IE中起作用:我创建了一个div,该div覆盖了页面的全部内容,并将其设置为position:relative和width / height:100%。 Then anytime, the modal dialog opens up, the position gets set to fixed. 然后随时可以打开模态对话框,将位置设置为固定。 That makes the overwflow:hidden work in old IE. 这使得溢出:在旧IE中隐藏工作。

Now, the other problem came up. 现在,另一个问题出现了。 When the user is at the bottom of the page and clicks on the links, dialog pops up, but the main page jumps up to the top. 当用户位于页面底部并单击链接时,将弹出对话框,但主页跳至顶部。

I want the main page to stay intact if possible. 我希望主页尽可能保持原样。 How can I do so? 我该怎么办?

Thank you. 谢谢。

The code to show/close the dialog: 显示/关闭对话框的代码:

show: 节目:

$('#allContent').css({ position: "fixed" });

$('#viewJobPanel').dialog('open');

$('#allContent').css('overflow', 'hidden');

close: 关:

$('#allContent').css('overflow', 'visible');
$('#allContent').css({ position: "relative" });
$('#viewJobPanel').dialog('destroy');

and when user clicks on the link, I have this event handlers 当用户单击链接时,我有此事件处理程序

e.preventDefault();
e.stopPropagation();

使用绑定到click事件的span而不是锚元素,可以避免重新放置窗口顶部的默认行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM