JavaScripts AD Carousel and timed pop-up and timed hide ads

Source: Internet
Author: User
Tags setinterval

Carousel Diagram:

The function is bound inside the body tag

3 images, 1.jpg 2.jpg 3.jpg using timed task execution to set picture properties Src uses a For loop to complete a 3-second replacement.

Timed pop-up ads:

Because the body tag is already bound to the function

So directly load the event function with window

The default display property for AD images is none

After 3 seconds, the display property of the ad image is set to block to form 3 seconds after the ad image is displayed.

Need to clean up the timer after popup

Then write a 3-second time hidden function, and finally to clean up the timing.

<script>functioninit () {//write a timed operation of the carousel graph displaySetInterval ("Changeimage ()", 3000); //set up timed actions to display ad imagesTime =setinterval ("Showad ()", 3000)            }            //writing function            varI=0functionChangeimage () {i++; //get picture position and set src property valuedocument.getElementById ("Img1"). src= ". /img/"+i+". jpg "; if(i==3) {i=0; }            }                        //2. Functions for displaying AD images            functionShowad () {//3. Get the location of your ad image                varAdele=document.getelementbyid ("Img2"); //4. Modify the attributes inside the ad image element to showadele.style.display= "Block"; //5. Clearly display the image of the timing operationclearinterval (time); //6. Set a timed action for a hidden picturetime1= setinterval ("Hiddenad ()", 3000); }                        //7. Functions for writing hidden AD images            functionHiddenad () {//8. Get the ad image and set the display value of its Style property to Nonodocument.getElementById ("Img2"). style.display= "None"; Clearinterval (time1)}</script>

JavaScripts AD Carousel and timed pop-up and timed hide ads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.