新手指引案例(js+css+cookie)

css部分:
.newtips{
    z-index:100;
    position: absolute;
    width:100%;
    height:100%;
    display: none;
}
.newtips .ts-cover{
    position:fixed;
    top:0;
    left:0;
    height: 1000px;
    background: rgba(0,0,0,.8);
}
.newtips .ts-con{
    width:100%;
    height:100%;
}
.newtips .ts-con > div{
    position: absolute;
    cursor:pointer;
    display:none;
    font-size:30px;
    line-height:1.6em;
    font-weight:bolder;
}
.newtips .ts-con .one{
    top: 310px;
    left: 415px;
    display:block;
}
.newtips .ts-con .two{
    top: 125px;
    right: 225px;
}
.newtips .ts-con .three{
    top: 175px;
    right: -20px;
}
.newtips .ts-con .fore{
    top: 580px;
    right: -40px;
}
.newtips .ts-con .five{
    color: #fff;
    top: 580px;
    left: calc(50% - 100px);
    text-align: center;
}
.newtips .five label{
   font-size: 14px;
   cursor: pointer;
}
.newtips .five input{
    width: 1.2em;
    height: 0.6em;
    vertical-align: middle;
}
html部分:
<div class="newtips hidden-xs">
    <div class="ts-cover">
    </div>
    <div class="ts-con">
        <div class="one">
                <img src="/images/tips/xuanzetip.png" alt="" >
                
        </div>
        <div class="two">
                <img src="/images/tips/yjjsTip.png" alt="" >
            
        </div>
         <div class="three">
                <img src="/images/tips/baogaotip.png" alt="" >
        </div>
        <div class="five">
            <p><img src="/images/tips/know.png" alt="" ></p>
            <label for="istips">以后不显示此提醒</label><input id="istips" type="checkbox" name="istips">
        </div>
    </div> 
</div>


js部分:
$(function () {
    var oIstips = document.getElementById('istips');
    if (getCookie('tips') === "" && $('.newtips').length === 1) {
        $('.newtips').css('display', 'block');
        var $Height = $(window).height() / 2;
        $('.newtips .ts-cover').width($(window).width());
        $('html,body').animate({ scrollTop: 400 }, 500);
        $('.newtips .ts-con > div').each(function () {
            $(this).click(function () {
                var $next = $(this).next();
                if ($next.length === 1) {
                    $(this).hide(500, function () {
                        $next.show();
                        $('html,body').animate({ scrollTop: $next.offset().top - $Height }, 500);
                    });
                } 
            });
        });
        $('.newtips .ts-con > div').eq(-1).find('p').eq(0).click(function (e) {
            if (oIstips.checked) {
                setCookie({
                    tips: 'no'
                }, 60);
            } else {
                setCookie({
                    tips: 'yes'
                }, 1);
            }
            $('.newtips').hide(500);
        });
    }
});
//设置cookie
function setCookie(vJson , time){
    var data = new Date( new Date().getTime() + time*24*60*60*1000 ).toGMTString();
    for (var key in vJson)document.cookie = key+"="+vJson[key]+"; expires="+data;
}


//获取cookie
function getCookie(key){
    var arr = document.cookie.match(new RegExp("(\\s|^)"+key+"=([^;]*)(;|$)"));
    return arr?arr[2]:"";
}


//移出cookie
function removeCookie(key){
    var json = {};
    json[key] = "";
    setCookie(json , -1);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值