drug95107
drug95107
2013-05-22 16:24

使用JQuery消失div - 如何在下次打开页面时停止重新加载

已采纳

I've got a div that disappears using jquery+css. It works beautifully, but I am running into a problem. How do I get that div to not reload the next time a user opens a page on same wordpress site. Because the div exists in header.php, everytime a new page is called so is the div, even if the user dismissed it before.

Is there a way to make sure that the banner is only loaded once per visit using the existing infrastructure I've got going? I feel like there must be some way to do this, especially since wordpress is run on php, but I am a bit out of my depth.

This is the website that I'm currently editing, and here is the code related to the banner.

HTML:

<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>  

JQUERY:

$(document).ready(function(){
$("#headershadow").hide();
$("#bigx").click(function(){
  $("#greenbanner").hide(1000);
  $("#headershadow").show();
});
});

CSS:

#greenbanner {
    width: 100%;
    height: 200px;
    background-color: #ffffff;
    background: rgba(248,80,50,1);
    background: -moz-linear-gradient(top, rgba(248,80,50,1) 0%, rgba(82,133,48,1) 0%, rgba(241,111,92,1) 0%, rgba(82,133,48,1) 0%, rgba(87,219,0,1) 0%, rgba(76,140,30,1) 83%, rgba(76,140,30,1) 100%);
    background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(248,80,50,1)), color-stop(0%, rgba(82,133,48,1)), color-stop(0%, rgba(241,111,92,1)), color-stop(0%, rgba(82,133,48,1)), color-stop(0%, rgba(87,219,0,1)), color-stop(83%, rgba(76,140,30,1)), color-stop(100%, rgba(76,140,30,1)));
    background: -webkit-linear-gradient(top, rgba(248,80,50,1) 0%, rgba(82,133,48,1) 0%, rgba(241,111,92,1) 0%, rgba(82,133,48,1) 0%, rgba(87,219,0,1) 0%, rgba(76,140,30,1) 83%, rgba(76,140,30,1) 100%);
    background: -o-linear-gradient(top, rgba(248,80,50,1) 0%, rgba(82,133,48,1) 0%, rgba(241,111,92,1) 0%, rgba(82,133,48,1) 0%, rgba(87,219,0,1) 0%, rgba(76,140,30,1) 83%, rgba(76,140,30,1) 100%);
    background: -ms-linear-gradient(top, rgba(248,80,50,1) 0%, rgba(82,133,48,1) 0%, rgba(241,111,92,1) 0%, rgba(82,133,48,1) 0%, rgba(87,219,0,1) 0%, rgba(76,140,30,1) 83%, rgba(76,140,30,1) 100%);
    background: linear-gradient(to bottom, rgba(248,80,50,1) 0%, rgba(82,133,48,1) 0%, rgba(241,111,92,1) 0%, rgba(82,133,48,1) 0%, rgba(87,219,0,1) 0%, rgba(76,140,30,1) 83%, rgba(76,140,30,1) 100%);
    margin-top: 5px;
}

#devices {
    height: 200px;
    margin-left: 5%;
}

#bigx {
    float: right;
    margin-bottom: 260px;
    margin-top: 10px;
    margin-right: 20px;
}
#bigx:hover {
    opacity: 0.4;
    filter:alpha(opacity=40);
    cursor: pointer;
}

#jointhedarkside {
    font-family: Geogrotesque, Lucida Sans Unicode, sans-serif;
    font-weight: 500;
    color: #ffffff;
    background-color: #57db00;
    border-radius: 5px;
    padding-top: 10px;
    padding-bottom: 10px;
    padding-right: 10px;
    padding-left: 10px;
    font-size: 18px;
    letter-spacing: normal;
    text-transform: uppercase;
    display: block; 
    float: left;
    line-height: 17px;
}
#jointhedarkside:hover {
    cursor: pointer;
    background-color: #46ab00;
}

    #bannertext {
        font-family: Geogrotesque, Lucida Sans Unicode, sans-serif;
        font-weight: 100;
        color: #ffffff;
        padding-top: 50px;
        margin-left: 80px;
        padding-right: 25px;
        padding-left: 5px;
        font-size: 30px;
        letter-spacing: normal;
        text-transform: uppercase;
        display: block; 
        float: left;
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douxing9813 douxing9813 8年前

    You'd set a cookie, and probably not even render the box in your PHP if it was found.

    点赞 评论 复制链接分享
  • doudi8829 doudi8829 8年前

    You can use the cookie feature in a javascript for this purpose . Store a value representing div status . Check every time when the page loads .

    点赞 评论 复制链接分享

相关推荐