[英]Javascript display none doesn't work while cookie
實時網站-http : //www.uposonghar.com/test/test_popup.html
我在該彈出窗口中添加了JavaScript cookie,因此如果有人單擊“如果不想再次看到此內容,請單擊此處!”。 按鈕,則將存儲cookie,如果存儲了cookie,則不會為他/她顯示彈出窗口。
一旦我單擊成功存儲的按鈕cookie,popup(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 display:block
//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>
您可以將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()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.