我就google一下,发现用js写的图片轮换效果例子是不少,可惜要么太繁琐,要么连页面都打不开
于是自己试了试,写了一个,代码很少。
js如下:
- $(document).ready(function(){
- $(".clickButton a").attr("href","javascript:return false;");
- $(".clickButton a").each(function(index){
- $(this).click(function(){
- changeImage(this,index);
- });
- });
- autoChangeImage();
- });
- function autoChangeImage(){
- for(var i = 0; i<=10000;i++){
- window.setTimeout("clickButton("+(i%5+1)+")",i*3000);
- }
- }
- function clickButton(index){
- $(".clickButton a:nth-child("+index+")").click();
- }
- function changeImage(element,index){
- var arryImgs = ["p_w_picpaths/01.jpg","p_w_picpaths/02.jpg","p_w_picpaths/03.jpg","p_w_picpaths/04.jpg","p_w_picpaths/05.jpg"];
- $(".clickButton a").removeClass("active");
- $(element).addClass("active");
- $(".imgs img").attr("src",arryImgs[index]);
- }