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=gb2312" /> <title>五张图片淡入淡出切换展示特效_武鸣人</title> <meta name="keywords" content="武鸣人网站,武鸣信息网,武鸣本地网,武鸣信息资源平台,减肥,健身,励志,励志语录,js特效,网页特效,www.wuming.ren"> <meta name="description" content="欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。"> <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_www_wuming_ren{position:relative;width:492px;height:172px;background:#fff;border-radius:5px;border:8px solid #fff;margin:10px auto;} #box_www_wuming_ren .list_www_wuming_ren{position:relative;width:490px;height:170px;overflow:hidden;border:1px solid #ccc;} #box_www_wuming_ren .list_www_wuming_ren li{position:absolute;top:0;left:0;width:490px;height:170px;opacity:0;filter:alpha(opacity=0);} #box_www_wuming_ren .list_www_wuming_ren li.current{opacity:1;filter:alpha(opacity=100);} #box_www_wuming_ren .count{position:absolute;right:0;bottom:5px;} #box_www_wuming_ren .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_www_wuming_ren .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_www_wuming_ren"); 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; //切换按钮 for (i = 0; i < aNum.length; i++) { aNum[i].index = i; aNum[i].onmouseover = function () { show(this.index) } } //武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) //鼠标划过关闭定时器 oBox.onmouseover = function () { clearInterval(play) }; //鼠标离开启动自动播放 oBox.onmouseout = function () { autoPlay() }; //自动播放函数 function autoPlay () { play = setInterval(function () { index++; index >= aImg.length && (index = 0); 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); //武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) 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); } };//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) </script> </head> <body> <a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr> <!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。--> <script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script> <script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script> <div id="box_www_wuming_ren"> <ul class="list_www_wuming_ren"> <li class="current"><img src="/img/20240223_www_wuming_ren_1.jpg" width="490" height="170" /></li> <li><img src="/img/20240223_www_wuming_ren_2.jpg" width="490" height="170" /></li> <li><img src="/img/20240223_www_wuming_ren_3.jpg" width="490" height="170" /></li> <li><img src="/img/20240223_www_wuming_ren_4.jpg" width="490" height="170" /></li> <li><img src="/img/20240223_www_wuming_ren_5.jpg" width="490" height="170" /></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>
本文来自武鸣人网站,转载请注明出处