We often see ads appear after a few seconds and then disappear. Let's use the JQuery framework to implement this function. The code is as follows: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Automatic display and hiding of advertisements</title> <style> #content{width:100%;height:500px;background:#999} </style> <!--Introduce jQuery--> <script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script> <script> /* need: 1. When the page is loaded, 3 seconds later. Automatically display ads 2. The ads will automatically disappear after being displayed for 5 seconds. analyze: 1. Use a timer to complete. setTimeout (execute a timer) 2. Analysis found that JQuery's display and hide animation effects are actually controlling display 3. Use the show/hide method to display the ad*/ //Entry function, after the page is loaded, define the timer and call these two methods$(function () { //Define a timer, call the adShow method and execute setTimeout(adShow,3000) once 3 seconds later; //Define a timer, call the adHide method, and execute setTimeout(adHide,8000) after 8 seconds; }); //Display ads function adShow() { //Get the ad div and call the display method $("#ad").show("slow"); } //Hide ads function adHide() { //Get the ad div and call the hide method $("#ad").hide("slow"); } </script> </head> <body> <!-- Overall DIV --> <div> <!-- Advertisement DIV --> <div id="ad" style="display: none;"> <img style="width:100%" src="../img/adv.jpg" /> </div> <!-- Main text below --> <div id="content"> Body part</div> </div> </body> </html> Directory structure:Running results:When I first entered, the ad did not appear. Three seconds later, the ad appears The ad will disappear after five seconds. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
>>: Detailed explanation of linux nslookup command usage
Table of contents Overview Install Gulp.js Create...
Table of contents 1. Introduction 2. Basic Concep...
Table of contents Linux netstat command 1. Detail...
CSS naming conventions (rules) Commonly used CSS ...
In daily development tasks, we often use MYSQL...
A sophomore asked me how to install and configure...
Often, we may need to export local database data ...
<body> <div id="root"> <...
Table of contents Overall Effect Listen for conta...
Table of contents Rendering API changes Render fu...
It is very simple to build a go environment under...
When doing a project, it is inevitable to encount...
1. Basic Concepts //Any container can be specifie...
This article uses an example to share with you a ...
Table of contents 1. What is a database? 2. Class...