【问题标题】:JQuery cookies + animation, DIVS, and wordpressjQuery cookie + 动画、DIVS 和 wordpress
【发布时间】:2013-05-18 06:00:07
【问题描述】:

我有以下setup,它运行良好,cookie 部分除外。 JQuery 由以下脚本控制:

$(document).ready(function () {
    $("#headershadow").hide();
    $("#greenbanner").show();
    $("#bigx").click(function () {
        $("#greenbanner").hide(1000);
        $("#headershadow").show(500);
        $.cookie('greencookie', 'true', {
            expires: 1,
            path: '/'
        });
    });
});

这是 HTML:

    <img src="<?php bloginfo('template_directory'); ?>/HeaderShadow.png" id="headershadow" />
    <div id="greenbanner">
        <img src="<?php bloginfo('template_directory'); ?>/Devices.png" id="devices">
        <img src="<?php bloginfo('template_directory'); ?>/bigx.png" id="bigx">
        <div id="bannertext">Spundge lets you discover, <br />curate, and create better content. <br /><br /><div id="jointhedarkside"><a style="color:#ffffff;" href="https://www.spundge.com/account/signup/">Get Started - It's Free</a></div>   </div>
    </div>  

我正在使用来自 GitHub 的 following cookies JQuery plugin,我似乎能够正确设置 cookie,但我不知道如何设置代码以便网页识别 cookie 并且不加载#greenbannerdiv。我尝试过的所有 if/else 组合都没有用。

请帮忙!

【问题讨论】:

    标签: jquery html css wordpress cookies


    【解决方案1】:

    告诉我它是否适合你:

    $(文档).ready(函数 () { $("#headershadow").hide(); if (!$.cookie('greencookie')){ $("#greenbanner").show(); } $("#bigx").click(function () { $("#greenbanner").hide(1000); $("#headershadow").show(500); $.cookie('greencookie', 'true', { 过期:1, 小路: '/' }); }); });

    如果没问题,我会添加一个关于我所做的简要说明。

    【讨论】:

    • 非常感谢您的回答!我将您的代码复制到网站 (blog.spundge.com) 但不幸的是它不起作用,即使在设置了 cookie 之后,每次打开新页面时 div 仍会重新加载。 :c 我想不出为什么没有任何效果。
    • 所以在 CSS 文件的第 1959 行添加一条 CSS 规则 display:none;。对于 div #greencookie 那么它只会在 cookie 不存在时出现
    猜你喜欢
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 2023-04-06
    • 1970-01-01
    • 2015-05-15
    • 1970-01-01
    相关资源
    最近更新 更多