zoukankan      html  css  js  c++  java
  • jquery.cookie广告弹窗点击关闭后一天弹一次

    jquery.cookie广告弹窗点击关闭后一天弹一次

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="description" content="">
        <meta name="keywords" content="">
        <title>简单利用jquery.cookie插件使弹窗点击关闭后一天弹一次</title>
        <style type="text/css">
            *{
                margin:0;
                padding:0;
            }
            
            .alert_windows{
                display:none;
                position:absolute;
                z-index:10;
                width:400px;
                height:300px;
                background:#566F93;
            }
            
            .alert_windows span{
                float:right;
                width:30px;
                height:30px;
                text-align:center;
                font:15px/30px Microsoft Yahei;
                cursor:pointer;
                color:#333;
                background:lightblue;
            }
            
            .alert_windows span:hover{
                color:#EEE;
                background:red;
            }
        </style>
        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script type="text/javascript" src="js/jquery.cookie.js"></script>
        <script type="text/javascript">
            $(function(){
                if($.cookie("isClose") != 'yes'){
                    var winWid = $(window).width()/2 - $('.alert_windows').width()/2;
                    var winHig = $(window).height()/2 - $('.alert_windows').height()/2;
                    $(".alert_windows").css({"left":winWid,"top":-winHig*2});    //自上而下
                    $(".alert_windows").show();
                    $(".alert_windows").animate({"left":winWid,"top":winHig},1000);
                    $(".alert_windows span").click(function(){
                        $(this).parent().fadeOut(500);
                        $.cookie("isClose",'yes',{ expires:1/8640});    //测试十秒
                        //$.cookie("isClose",'yes',{ expires:1});        一天
                    });
                }
            });
        </script>
    </head>
    
    <body>
        
        <div style="font-size:24px;360px;margin:40px auto;">提示:一天弹一次,关闭了就没了</div>
        
        <div class="alert_windows">
            <span>X</span>
        </div>
    </body>
    </html>
    jquery.cookie.js
    /*jquery.cookie start*/
    jQuery.cookie = function(name, value, options) { 
          if (typeof value != 'undefined') { 
                    options = options || {}; 
                    if (value === null) { 
                              value = ''; 
                              options = $.extend({}, options); 
                              options.expires = -1; 
                    } 
                    var expires = ''; 
                    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 
                              var date; 
                              if (typeof options.expires == 'number') { 
                                        date = new Date(); 
                                        date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));     //这里改时间,单位毫秒,默认为1天。
                              } else { 
                                        date = options.expires; 
                              } 
                              expires = '; expires=' + date.toUTCString(); 
                    } 
                    var path = options.path ? '; path=' + (options.path) : ''; 
                    var domain = options.domain ? '; domain=' + (options.domain) : ''; 
                    var secure = options.secure ? '; secure' : ''; 
                    document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 
          } else { 
                    var cookieValue = null; 
                    if (document.cookie && document.cookie != '') { 
                              var cookies = document.cookie.split(';'); 
                              for (var i = 0; i < cookies.length; i++) { 
                                        var cookie = jQuery.trim(cookies[i]); 
                                        if (cookie.substring(0, name.length + 1) == (name + '=')) { 
                                                  cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 
                                                  break; 
                                        } 
                              } 
                    } 
                    return cookieValue; 
          } 
    }; 
    /* jquery.cookie end */
  • 相关阅读:
    cad是什么意思?教你快速把cad转换成pdf格式
    为什么街上的商贩更喜欢用微信支付,而不是支付宝,看完长知识了
    音乐剪辑软件怎么用?教你一个快速编辑音频的方法
    电脑如何录制视频?安利两种电脑录屏的方法
    被称为逆天改命的5大中国工程,曾轰动世界,你知道几个?
    如何使用音乐格式转换器?快速编辑音频文件的方法
    PPT结尾只会说“谢谢”?学会这些PPT结尾,观众主动为你鼓掌
    经典PHP面试题(冒泡排序),当场就被打脸,卧槽什么冒泡?为啥还排序?
    千万不要再搞混了,函数empty( var );输出的判断值是false : true
    PHP删除数组中空数组
  • 原文地址:https://www.cnblogs.com/li-sir/p/7766742.html
Copyright © 2011-2022 走看看