2 打开模式对话框时可见滚动条 [英] 2 Scrollbars visible when I open a modal dialog

查看:46
本文介绍了2 打开模式对话框时可见滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个莫名其妙的问题,当我们尝试从父页面打开一个模式对话框时,它打开时有 2 个彼此相邻的垂直滚动条.一个控制模态框,另一个控制它后面的主页.

We have a baffling issue whereby when we try to open a modal dialog box from a parent page it opens with 2 vertical scrollbars next to each other. One controls the modal box, the other one controls the main page behind it.

拥有 2 个滚动条并不理想,并已尝试为此实施解决方案.我们在对话框页面中添加了一些 javascript,它会在模式对话框打开时将样式设置为溢出:隐藏.

To have 2 scrollbars is not ideal and have tried to implement a solution for this. We added some javascript in the dialog box page which would set the style to overflow:hidden when the modal dialog is open.

<script>
function myOnLoad() {
    window.parent.$('body').css('overflow', 'hidden');
}

并使用....

<body onload="myOnLoad()">

这有效并有效地删除了它后面页面中的滚动条(即它做了它应该做的事情)但是我们还想在模态对话框关闭时将溢出设置回自动"......

This works and effectively removes the scrollbar in the page behind it (i.e it does what it should) however we also want to set the overflow back to ‘auto’ when the modal dialog is closed…

我们通过添加此代码来完成此操作..

We have done this by adding this code..

<script type="text/javascript">
// close Modal
$("#close").click(function () {
window.parent.$('body').css('overflow', 'auto');
window.parent.$("iframe").attr('src', '');
window.parent.$(".modalDialog").removeClass('show');
});

然而,这似乎不起作用,因为模式对话框关闭但滚动条仍然隐藏在主页上.谁能告诉我我在这里可能做错了什么?我尝试了不同的溢出属性,但似乎没有任何效果

However this does not seem to work as the modal dialog closes but the scrollbar is still hidden on the main page. Can anyone tell me what I might be doing wrong here? I have tried different overflow properties but nothing seems to work

推荐答案

好的,试试这个,我认为你的页面在点击时重新加载并因此执行你的加载:

Ok try this, I think your page is reloading on click and thus executing your onload:

$("#close").click(function (e) {
e.preventDefault();
window.parent.$('body').css('overflow', 'auto');
window.parent.$("iframe").attr('src', '');
window.parent.$(".modalDialog").removeClass('show');
});

这篇关于2 打开模式对话框时可见滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆