图片轮换
2013-09-30 08:08
176 查看
<html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> </head> <script> var arr = Array('one','two','three','four','five'); var pic;//图片对象 var i = 0;//计数 var time; function $(x){ return document.getElementById(x); } function $n(x){ return document.getElementsByTagName(x); } function picture(){ this.time = function(){ window.clearInterval(time); time = window.setInterval('pic.display()',1000);//先让图片动起来 } this.display = function(){ var len = arr.length; i++; if(i>=len){ i=0; } $n('img')[0].src = './images/'+arr[i]+'.jpg'; this.background_img(); } //stop this.stop = function(){ window.clearInterval(time); } //start this.start = function(){ this.time(); } //下标 this.xiabiao = function(value){ var x; //遍历找出value在数组中的下标 for(var j=0,len=arr.length;j<len;++j){ if(arr[j] == value){ x = j; } } return x; } //按钮(value是鼠标碰到图片切换按钮时的值) this.img = function(value){ window.clearInterval(time); //找下标(方法) i = this.xiabiao(value); $n('img')[0].src = './images/'+arr[i]+'.jpg'; //自动切换按钮背景色css this.background_img() } //图片自动切换按钮背景色 this.background_img = function(){ //alert(i); for(var x=0,len=arr.length;x<len;++x){ if(x != i){ $(arr[x]).style.background = ''; } $(arr[i]).styl 9dae e.background = 'red'; } } } //控制器 window.onload = function(){ pic = new picture();//实例化一个图片类对象 pic.time(); $n('img')[0].onmouseover = function(){pic.stop();}; $n('img')[0].onmouseout = function(){pic.start();}; //鼠标离开自动切换按钮区域开始图片转换 $('div1').onmouseover = function(){ for(var j=0,len=arr.length;j<len;j++){ $(arr[j]).onmouseout = function(){pic.start();}; } } } </script> <style> body{ margin:0px; padding:0px; text-align:center; } #xiaomi{ width:940px; height:410px; margin:auto; text-align:left; } #div1{ width:200px; height:20px; background:blue; float:right; } #one,#two,#three,#four,#five{ height:20px; width:20px; background:green; float:left; } .bai{ height:20px; width:20px; background:white; float:left; } </style> <body> <div id="xiaomi"> <img src="./images/one.jpg"></img> <div id="div1"> <div class="bai"></div><div id="one" onmouseover="pic.img('one')"></div> <div class="bai"></div><div id="two" onmouseover="pic.img('two')"></div> <div class="bai"></div><div id="three" onmouseover="pic.img('three')"></div> <div class="bai"></div><div id="four" onmouseover="pic.img('four')"></div> <div class="bai"></div><div id="five" onmouseover="pic.img('five')"></div> <div> </div> </body> </html>
相关文章推荐
- 动态图片渐变轮换效果
- jQuery插件-轻量图片轮换-UISlide
- jquery后台登录页面背景图片自动轮换登录界面代码
- js类似新闻图片轮换(带有文字介绍,其实可以放任何内容)
- Jquery 实现图片轮换
- Flash 图片轮换效果
- slide 图片轮换
- JS实现图片轮换效果
- ASP.NET实现图片轮换
- Jquery 实现图片轮换
- CSDN轮换广告图片轮换效果
- js图片轮换显示实例
- Js_图片轮换
- jsp+css实现图片自动轮换
- jquery 图片轮换 潇湘博客
- javascript实现图片左右轮换效果(鼠标控制亦可)
- 简单的图片自动轮换
- 享受 Bcastr 4.0,优秀的通用图片轮换播放器~~
- 自己东手写个jquery图片轮换效果
- 超经典jquery+CSS+DIV实现图片轮换效果