在x秒后向上滑动面板,单击关闭 - SET COOKIE

时间:2011-11-17 16:49:22

标签: jquery cookies slideup

希望有人能指出我正确的方向。

我们正在尝试改进对邮件列表的订阅。当用户在x秒后访问我们的网站时,我想要一个面板向上滑动,要求他们注册邮件列表。

如果他们点击任何按钮(注册,关闭,不再显示)我想设置一个cookie,以便面板不再显示。

我已经掌握了向上/向下滑动但我在饼干方面是新手并且不确定如何设置它以便在设置cookie时,幻灯片动作不再发生。

这是我的jQuery ......

// MAILING LIST SLIDER //
        // set a delay of 3 seconds before mailing list panel appears 
        $("#mailingListPanelSlide").delay(3000).slideDown("slow");

        // set triggers to close the mailing list panel & set cookie
        $("a#closeButton, p.negativeActionFormButton").click(function(){
            $("div#mailingListPanelSlide").slideUp("slow");
            $.cookie("mailingListPanel", "dontshow");
            }); 

        // HELP!!!! if cookie is set to collapsed, then don't perform slide down/hide panel altogether?
        var mailingListPanel = $.cookie("mailingListPanel");
        if (mailingListPanel == "dontshow") {
            $("div#mailingListPanelSlide").css("display","none");
            };


        //END MAILING LIST SLIDER //    

2 个答案:

答案 0 :(得分:2)

如果你想使用$ .cookie,你必须拥有jQuery cookie插件 https://github.com/carhartl/jquery-cookie

if($.cookie("mailingListPanel") !== 'dontshow'){
    // set a delay of 3 seconds before mailing list panel appears 
    $("#mailingListPanelSlide").delay(3000).slideDown("slow");
}else{
    $("div#mailingListPanelSlide").css("display","none");
}
// set triggers to close the mailing list panel & set cookie
$("a#closeButton, p.negativeActionFormButton").click(function(){
    $("div#mailingListPanelSlide").slideUp("slow");
    $.cookie("mailingListPanel", "dontshow");
}); 

答案 1 :(得分:1)

   if ($.cookie("mailingListClosed") == null && $.cookie("mailingListNeverShow") == null) {
            $("#mailingListPanelSlide").delay(4000).slideDown("slow");
        };

        // Trigger for close panel button. Close panel and set session cookie
        $("a#closeButton").click(function () {
            $("div#mailingListPanelSlide").slideUp("slow");
            $.cookie("mailingListClosed", "true", { path: "/" });
        });

        // Trigger for never show panel button. Close panel and set persistent cookie
        $("p.negativeActionFormButton").click(function () {
            $("div#mailingListPanelSlide").slideUp("slow");
            $.cookie("mailingListNeverShow", "true", { expires: 365, path: "/" });
        });

        // Set persistent cookie if user clicks on the newsletter button as well
        $("p.genericLinkButton").click(function () {
            $.cookie("mailingListNeverShow", "true", { expires: 365, path: "/" });
        });