zoukankan      html  css  js  c++  java
  • JavaScript对象(document对象 图片轮播)

    图片轮播:

    需要注意的HTML需要img标签,他和input标签一样,是非封闭的标签

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>广告轮播</title>
    <script src="广告轮播.js"></script>
    </head>
    
    <body>
    <img id="img1" src="image/rose.jpg" />
    </body>
    </html>

    JavaScript:

    现在只需要改变JavaScript中数组元素的值即可改变图片

    // JavaScript Document
    var imageArray = ['apple.jpg','rose.jpg'];
    
    var timer;
    var index = 1;
    function rotateFunc(){
        var img = document.getElementById("img1");
        img.src = "image/"+imageArray[index];
        
        if(index==imageArray.length-1)
            index = 0;
        else
            index++;
        }
    
    function startRotate(){
        timer = window.setInterval(rotateFunc,1000);
        }
    window.addEventListener('load',startRotate,false);
  • 相关阅读:
    luogu P3801 红色的幻想乡
    [USACO07OPEN]吃饭Dining
    [SCOI2007]蜥蜴
    [SDOI2011]染色
    [USACO07DEC]Sightseeing Cows
    [HNOI2007]紧急疏散EVACUATE
    [ZJOI2009]假期的宿舍
    [SDOI2013]费用流
    [CQOI2009]跳舞
    使用chrony安装chrony
  • 原文地址:https://www.cnblogs.com/fengdashen/p/5117213.html
Copyright © 2011-2022 走看看