html - Internet Explorer z-index 问题

标签 html css internet-explorer internet-explorer-8 z-index

我可以找到很多与 Internet Explorer 相关的 z-index 问题,但这些解决方案对我不起作用或者我无法正确理解它。

我有一个表单元素。

单击表单提交后,我想用 div 覆盖表单,以便无法单击表单中的任何内容。为此,我使用了一个位置正确的叠加层,并且 js 也工作正常。它在 chrome 中完美运行,但在 IE8 中 z-index 不工作。

到目前为止我已经尝试过了

1.

<div style="position:absolute; z-index:100"></div>
<form></form>

2.

<div style="position:absolute; z-index:100"></div>
<form style="position:relative; z-index:50"></form>

3.

<div style="position:relative; z-index:50">
<div style="position:absolute; z-index:100"></div>
</div>
<form style="position:relative; z-index:50"></form>

4.

<div style="position:relative; z-index:50">
<div style="position:absolute; z-index:100"></div>
<form style="position:relative; z-index:50"></form>
</div>

我怎样才能让它在 IE8 中工作?所有这些在 chrome 中都可以正常工作。

最佳答案

Mike Alsup 的 BlockUI插件几乎已经做了你想要完成的事情。我经常使用它,以至于我编写了几个扩展方法来使用我经常使用的选项调用插件:

if ($.blockUI) {
    /* 
    *   Extension method to display/hide loading element for long-running tasks
    *   @@requires: jquery.blockUI.js
    */
    $.fn.loading = function (opt) {
        // clear out plugin default styling 
        $.blockUI.defaults.css = {};

        if (opt === 'start') {
            this.block({
                message: '<div class="loading"><i class="fa fa-refresh fa-4x fa-spin"></i></div>',
                css: {
                    border: 'none',
                    backgroundColor: 'none',
                    color: '#fff'
                }
            });
        }
        else {
            this.unblock();
        }
    };


    /* 
    *   Extension method to display/hide viewport-wide loading element for long-running tasks
    *   @@requires: jquery.blockUI.js
    */
    $.toggleOverlay = function toggleOverlay(opt) {
        if (opt === 'start') {
            $.blockUI({
                message: '<div class="loading"><p><i class="fa fa-refresh fa-4x fa-spin"></i><p><p>Loading. Please wait...</p></div>',
                css: {
                    border: 'none',
                    backgroundColor: 'none',
                    color: '#fff'
                }
            });
        }
        else {
            $.unblockUI();
        }
    }
}

我正在使用的标记假定您也在使用 FontAwesome,但可以将其更改为任何适合您的船。使用这两个扩展,您可以将叠加层添加到特定部分

$('#form').loading('start') // to start the overlay
$('#form').loading('end') // to end the overlay

或者为整个视口(viewport)添加一个叠加层

$.toggleOverlay('start') // to start overlay
$.toggleOverlay('end') // to end overlay

否则,只需按照插件页面上的示例进行操作即可。

关于html - Internet Explorer z-index 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25561733/

相关文章:

javascript - 使用 jQuery 在另一个 div 中克隆一个 div

html - 如何并排移动图像?

javascript - IE7 中非常奇怪的 JavaScript 错误

jquery - 将 div 克隆到 obj 中并对其进行操作

java - 使用 Jsoup 删除元素不起作用

html - 在这种情况下,如何将多行文本居中放置在图像上?

javascript - 是否可以从 Internet Explorer 中动态插入的 QuickTime <object> 启用 DOM 事件

internet-explorer - 使用多个 IE 的 IE6 不允许我编辑文本框

javascript - 如何从 Ant design 的 Select/Option 组件中获取值

javascript - 无法让移动图像在点击时消失