During major festivals, the homepages of major mainstream websites will be dressed in festive attire. Designers generally use large background images to obtain better visual impact. Of course, some users must also be considered. background image, then it is necessary to place a "Close" button on the background image. As long as the user clicks the "Close Background" button, the large background image will disappear.
We use javascript to control the display and hiding of the background image. When the close button is clicked, the CSS is controlled so that the page does not load the background image. At the same time, COOKIE related parameters are recorded, and the validity period of the cookie is set. Then the page is refreshed within the cookie validity period. The background image will not be loaded again. If the cookie expires, the background image will be reloaded.
HTML
Generally, the close button of the background image is placed at the head of the page. We place the button to close the background at the top of the page. Of course, this button is a ready-made image.
CSS
We also need to prepare a large background image. We find a large background image from the Internet and use CSS to make a simple page layout.
After deploying the css, the page has no effect yet. We need to use javascript to load the background image.
Javascript
When the page is loaded for the first time (no cookies, etc. have been set at this time), of course the background image must be loaded to display the complete page effect. When we click the "Close" button, Javascript will kill the background image that has been loaded on the page, that is, not display it, and set a cookie to control whether the large background image is displayed through the expiration time of the cookie. That is, when the page is refreshed next time, if the cookie has not expired, the large background image will not be loaded. Otherwise, the large background image will be loaded. Please see the code:
Obviously, we control the loading of the background image by setting the CSS background attribute of the page element, and read and set cookies through two custom functions, getCookie() and setCookie().