国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JS實現可切換圖片的幻燈切換效果示例

2019-11-19 11:28:44
字體:
來源:轉載
供稿:網友

本文實例講述了JS實現可切換圖片的幻燈切換效果。分享給大家供大家參考,具體如下:

<!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>JS切換圖片幻燈切換效果</title>  <style>    body, div, ul, li { margin: 0; padding: 0; }    ul { list-style-type: none; }    body { background: #000; text-align: center; font: 12px/20px Arial; }    #box { position: relative; width: 322px; height: 172px; background: #fff; border-radius: 5px; border: 8px solid #fff; margin: 10px auto; }    #box .list { position: relative; width: 320px; height: 240px; overflow: hidden; border: 1px solid #ccc; }    #box .list li { position: absolute; top: 0; left: 0; width: 320px; height: 240px; opacity: 0; filter: alpha(opacity=0); }    #box .list li.current { opacity: 1; filter: alpha(opacity=100); }    #box .count { position: absolute; right: 0; bottom: 5px; }    #box .count li { color: #fff; float: left; width: 20px; height: 20px; cursor: pointer; margin-right: 5px; overflow: hidden; background: #F90; opacity: 0.7; filter: alpha(opacity=70); border-radius: 20px; }    #box .count li.current { color: #fff; opacity: 1; filter: alpha(opacity=100); font-weight: 700; background: #f60; }    #tmp { width: 100px; height: 100px; background: red; position: absolute; }  </style>  <script type="text/javascript">    window.onload = function() {      var oBox = document.getElementById("box");      var aUl = document.getElementsByTagName("ul");      var aImg = aUl[0].getElementsByTagName("li");      var aNum = aUl[1].getElementsByTagName("li");      var timer = play = null;      var i = index = 0;      var bOrder = true;      //切換按鈕      for(i = 0; i < aNum.length; i++) {        aNum[i].index = i;        aNum[i].onmouseover = function() {          show(this.index)        }      }      //鼠標劃過關閉定時器      oBox.onmouseover = function() {        clearInterval(play)      };      //鼠標離開啟動自動播放      oBox.onmouseout = function() {        autoPlay()      };      //自動播放函數      function autoPlay() {        play = setInterval(function() {          //判斷播放順序          bOrder ? index++ : index--;          //正序          index >= aImg.length && (index = aImg.length - 2, bOrder = false);          //倒序          index <= 0 && (index = 0, bOrder = true);          //調用函數          show(index)        }, 2000);      }      autoPlay();//應用      function show(a) {        index = a;        var alpha = 0;        for(i = 0; i < aNum.length; i++)aNum[i].className = "";        aNum[index].className = "current";        clearInterval(timer);        for(i = 0; i < aImg.length; i++) {          aImg[i].style.opacity = 0;          aImg[i].style.filter = "alpha(opacity=0)";        }        timer = setInterval(function() {          alpha += 2;          alpha > 100 && (alpha = 100);          aImg[index].style.opacity = alpha / 100;          aImg[index].style.filter = "alpha(opacity = " + alpha + ")";          alpha == 100 && clearInterval(timer)        }, 20);      }    };  </script></head><body><div id="box">  <ul class="list">    <li class="current"><img src="img/3.jpg" width="320" height="240"/></li>    <li><img src="img/1.jpg" width="320" height="240"/></li>    <li><img src="img/2.jpg" width="320" height="240"/></li>    <li><img src="img/3.jpg" width="320" height="240"/></li>    <li><img src="img/4.jpg" width="320" height="240"/></li>  </ul>  <ul class="count">    <li class="current">1</li>    <li>2</li>    <li>3</li>    <li>4</li>    <li>5</li>  </ul></div></body></html>

更多關于JavaScript相關內容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結》、《JavaScript查找算法技巧總結》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調試技巧總結》、《JavaScript數據結構與算法技巧總結》及《JavaScript數學運算用法總結

希望本文所述對大家JavaScript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 雅江县| 罗源县| 丰都县| 隆昌县| 绥芬河市| 德保县| 凉城县| 施甸县| 黄大仙区| 南川市| 灵石县| 丹凤县| 青铜峡市| 济阳县| 沙洋县| 上思县| 定西市| 平顺县| 昌江| 华坪县| 山丹县| 泌阳县| 桦川县| 安庆市| 且末县| 衡阳市| 上犹县| 镇赉县| 万宁市| 多伦县| 昌平区| 三河市| 安图县| 平罗县| 泽库县| 永嘉县| 旺苍县| 衡水市| 平遥县| 普兰店市| 县级市|