如何在关闭模态弹出框时阻止页面刷新>

时间:2018-02-08 01:18:28

标签: javascript jquery modal-dialog popup

因此每次关闭弹出模式时,页面都会刷新,弹出窗口会再次出现,那么一旦用户点击关闭,如何阻止页面刷新并让弹出窗口淡出?

我不确定是否使用e.preventDefault();会做的。

以下是我的代码。谢谢。

top

1 个答案:

答案 0 :(得分:0)

您需要传递参数e

$(".popup-close").click(function(e){
            closeSPopup(e);
        });

用户点击关闭后不显示滚动,请尝试此

$(document).scroll(function(){
    console.log('scrolling - '+$("#mc_embed_signup").data('userClosed'));
    if (!$("#mc_embed_signup").data('userClosed')) {
        $(".popup-close").click(function(e){
            closeSPopup(e);
        });

        var a = $(this).scrollTop();
        if (a > 500) {
            $("#mc_embed_signup").fadeIn();
        }
    }
});

function closeSPopup(e){
    e.preventDefault();
    $("#mc_embed_signup").data('userClosed',true);
    $("#mc_embed_signup").fadeTo("slow", 0, function(){
        //fadeto only set the opacity and doesn't actually hide the div
        //So you need to hide the div after fadeto
        $("#mc_embed_signup").hide();
    }); //check fadeto here http://api.jquery.com/fadeTo/
}
相关问题