简体   繁体   English

覆盖透明div一次单击

[英]overlay transparent div one time click

I referred to this thread to get a transparent div to display on top of the web site content and make it disappear when clicking on it... 我提到这个线程是为了获得一个透明的div,以使其显示在网站内容的顶部,并使其在单击时消失。

however, when someone visits a page within the site and they click on the home button they are displayed the transparent div again... is there a way to have the div appear only one time and do not appear again after they close it? 但是,当某人访问站点中的页面并单击主页按钮时,它们再次显示为透明div ...是否可以使div仅显示一次,而在关闭后不再显示?

The best way to do is by setting a cookie. 最好的方法是设置cookie。 On this way, you can hide it forever, or hide it for a specified time. 这样,您可以将其永久隐藏或将其隐藏指定的时间。

document.cookie = "transparentdivShow = false";

And now you can check if this cookie exists, and if so, don't show the div: 现在,您可以检查此cookie是否存在,如果存在,则不显示div:

if(document.cookie.indexOf("transparentDivShow") >= 0) {
    return true; // Don't show it
} else {
    return false; // Show the div
}

As the above poster mentioned, you could use a cookie. 正如上面提到的那样,您可以使用cookie。 Alternatively, you could use HTML5 Local Storage! 另外,您可以使用HTML5本地存储! Local Storage allows data to be stored locally within a user's browser. 本地存储允许将数据本地存储在用户的浏览器中。

In this instance, you could have something like a clickcounter that counts to see if the clickcounter is greater than 1. If it is greater than 1, give the div a hidden attribute or just get rid of it. 在这种情况下,您可能会有类似clickcounter之类的东西来计数,以查看clickcounter是否大于1。如果大于1,则为div提供隐藏属性或直接删除它。

if (sessionStorage.clickcounter) {
 <div hidden> You can't see me. I'm invisible. </div>
} else {
 sessionStorage.clickcounter = 1;
 <div visible> Hi! I'm not transparent. </div>
}

I hope that this helps. 我希望这个对你有用。 Here's a page with more information on it as well! 这也是一个包含更多信息的页面! http://www.w3schools.com/html/html5_webstorage.asp http://www.w3schools.com/html/html5_webstorage.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM