zoukankan      html  css  js  c++  java
  • JS随机抽取图片

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     5     <title></title>
     6     <meta charset="utf-8" />
     7     <style>
     8         #div1 {
     9              100%;
    10             background: url(1.jpeg) center top no-repeat;
    11             height: 400px;
    12         }
    13 
    14         input {
    15             display: block;
    16              80px;
    17             height: 40px;
    18             text-align: center;
    19             margin: 0 auto;
    20             font-family: "微软雅黑";
    21         }
    22     </style>
    23     <script>
    24         window.onload = function () {
    25             var imgs = ["1.jpeg", "2.jpeg", "3.jpeg", "4.jpeg", "5.jpeg"];
    26             function show() {
    27                 var i = Math.ceil(Math.random() * 5);//有几张图片就乘以几
    28                 document.getElementById("div1").style.backgroundImage = "url(" + imgs[i - 1] + ")"
    29             }
    30             var timeout = setInterval(show, 1000);//每隔1秒改变一次
    31 
    32             var x = 0;
    33             document.getElementById("ip").onclick = function () {              
    34                 document.getElementById("ip").innerHTML = x;
    35                 x++;
    36                 if (x % 2 != 0) {
    37                     this.style.backgroundColor = "#0ff";
    38                     clearInterval(timeout);
    39                 }
    40                 else {
    41                     this.style.backgroundColor = "#E1E1E1";
    42                     timeout = setInterval(show, 1000);
    43                 }
    44             }
    45         }
    46     </script>
    47 </head>
    48 
    49 <body>
    50     <div id="div1">
    51     </div>
    52     <div>
    53         <input type="button" value="暂停" id="ip" />
    54     </div>
    55 </body>
    56 </html>
  • 相关阅读:
    linux下导入、导出mysql 数据库命令
    MapReduce工作原理(简单实例)
    BloomFilter ——大规模数据处理利器
    huawei机试题目
    二叉树操作集锦
    表达式计算的中序转后序
    用 JavaScript 修改样式元素
    网页中的表单元素
    使用网络字体作为矢量图标
    CSS 的 appearance 属性
  • 原文地址:https://www.cnblogs.com/zhang1997/p/8317944.html
Copyright © 2011-2022 走看看