直播网站 - http://www.uposonghar.com/test/test_popup.html
我在弹出窗口中添加JavaScript cookie,如果有人点击“如果不想再看到这个就点击这里!”按钮然后将存储cookie,如果存储了cookie,则不会为他/她显示弹出窗口。
一旦我点击成功存储的按钮cookie,弹出窗口(id-myModal)就会消失,但弹出bg / overlay(id-reveal-modal-bg)会出现。我添加该代码,但这不起作用 -
if(getCookie('abc')=="def" && document.getElementById('myModal'))
document.getElementById('myModal').style.display="none";
document.getElementById('reveal-modal-bg').style.display="none";
js页面上有一个css,可能会将display:none
覆盖为display:block
- http://www.uposonghar.com/test/jquery.reveal.js
js页面代码 -
if(options.animation == "none") {
modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
modalBG.css({"display":"block"});
unlockModal()
}
完整代码 -
<script type="text/javascript">
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value + ";path=/";
}
function getCookie(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}
if(getCookie('abc')=="def" && document.getElementById('myModal'))
document.getElementById('myModal').style.display="none";
document.getElementById('reveal-modal-bg').style.display="none";
</script>
答案 0 :(得分:1)
您可以将jquery.reveal.js中的javascript更改为
if(options.animation == "fadeAndPop" && getCookie('abc')!="def") {
modal.css({'top': $(document).scrollTop()-topOffset, 'opacity' : 0, 'visibility' : 'visible'});
modalBG.fadeIn(options.animationspeed/2);
modal.delay(options.animationspeed/2).animate({
"top": $(document).scrollTop()+topMeasure + 'px',
"opacity" : 1
}, options.animationspeed,unlockModal());
}
if(options.animation == "fade" && getCookie('abc')!="def") {
modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(document).scrollTop()+topMeasure});
modalBG.fadeIn(options.animationspeed/2);
modal.delay(options.animationspeed/2).animate({
"opacity" : 1
}, options.animationspeed,unlockModal());
}
if(options.animation == "none" && getCookie('abc')!="def" ) {
modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
modalBG.css({"display":"block"});
unlockModal()
}