js实现图片自动切换效果。
js实现图片自动切换效果,简单实用,原谅我只是一只小菜鸟还在学大神天天写博文装逼。
<script language="javascript"> setInterval(test, 2000); var array = new Array(); var index = 0; var array = new Array("../../Content/images/3s1hj_kqzew4k2ozbhs2dwgfjeg5sckzsew_780x520.jpg", "../../Content/images/3s1hj_kqzewqs2ozbhsrdwgfjeg5sckzsew_450x600.jpg", "../../Content/images/3s1hj_kqzfc4leozbhmtcugfjeg5sckzsew_650x975.jpg"); function test() { var myimg = document.getElementById("imgs"); if (index == array.length - 1) { index = 0; } else { index++; } myimg.src = array[index]; } </script>
在页面需要的地方添加这个:
↓
↓
↓
<img style="width:200px; height:200px" id="imgs" src="../../Content/images/3s1hj_kqzdoqs2ozbhsq3wgfjeg5sckzsew_450x600.jpg" />