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

发布于 2024-12-16 17:21:31 字数 1047 浏览 1 评论 0原文

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

我们正在努力改善邮件列表的订阅。当用户在 x 秒后访问我们的网站时,我希望有一个面板向上滑动,要求他们注册邮件列表。

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

我已经掌握了向上/向下滑动,但我是 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 //    

hoping someone can point me in the right direction.

We're trying to improve subscriptions to our mailing list. When a user visits our site after x amount of seconds, i'd like a panel to slide up asking them to sign up to the mailing list.

If they click any of the buttons (sign up, close, dont show again) I want to set a cookie so the panel doesn't show again.

I've mastered the slide up/down BUT i'm a newbie at the cookie side of things and not sure how to set it so when the cookie is set, the slide action doesn't occur again.

Here's my 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 //    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

亽野灬性zι浪 2024-12-23 17:21:31

如果你想使用 $.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");
}); 

You must have the jQuery cookie plugin if you want to use $.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");
}); 
淡淡的优雅 2024-12-23 17:21:31
   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: "/" });
        });
   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: "/" });
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文