0

我正在使用模式窗口调用登录(它在 Worpress 中,但登录另一个服务)。我正在尝试添加一个按钮来关闭模式窗口 - 看起来它应该可以工作,但它不是......任何想法?

这是我正在使用的js:

<script type="text/javascript">
function overlay() {
    el = document.getElementById("overlay");
    el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
$(function(){// document.ready shorthand
    $('.close-btn').click(function() {
        $('#overlay,.login-popup').fadeOut('3000',function(){//use 3000 in place of 300m
            $('#overlay').remove();
        });    
        return false;
    });
});

</script>

关闭按钮的 html:

<a class="close-btn" href="#">Close</a>

和CSS:

#overlay {
 visibility: hidden;
 position: absolute;
 left: 0px;
 top: 0px;
 width:100%;
 height:100%;
 text-align:center;
 z-index: 1000;
 background-image:url(../background_trans.png);
 background-repeat:repeat;
}

#overlay_content {
 width:275px;
 width:19.64285714rem;
 margin: 100px auto;
 background-color: #ebf1e3;
 border:1px solid #ccc;
 padding:25px;
 text-align:left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
line-height:175%;
}
4

1 回答 1

0

不要remove()覆盖元素,只需将其隐藏并将其visibility:hidden设置.html()为null,但仅当您想擦除模式窗口中当前的内容时。

来源:我最近做了类似的事情(阅读 elements.js 源代码并在网格中移动以启动模式弹出窗口)(http://fooscript.com/zombie/

这是我用来清除模态的代码

clearModal : function() {
    this.modal.innerHTML = null;
    this.triggerOverlay();
},
//when called, triggers the visibility of the overlay that disables the page
//modal window
triggerOverlay : function() {
    this.overlay.style.visibility = (this.overlay.style.visibility == "visible") ? "hidden" : "visible";
},
于 2014-02-24T22:57:44.793 回答