另一方面就是css的编写,setInterval和setTimeout的用法,前者是每隔多长时间执行一次,后者是多长时间执行一次;
关于setTimeout的用法 有二种形式 1 setTimeout(code,interval) 中的code是字符串
2 setTimeout(func,interval,args) 中的func是函数
实现代码 jquery slidepictrue script> $(function(){ $imageShow=$("#imageShow"); $images=$("#imageSrc li",$imageShow); $imageSwitches=$("#imageSwitch li",$imageShow); //判断图片的张数,如果有图片 if($images.size()>0){ init(); //利用setInterval设置延迟时间,一直执行每隔1秒执行autoSwitch函数, var timer=setInterval(autoSwitch,1000); //遍历函数 $imageSwitches.each(function(index,item){ $(item).click(function(){ clearInterval(timer); // setTimeout有二种形式,第一种 setTimeout(code,interval),code是字符串,第二种 // setTimeout(func,interval,args),func是函数表达式,而不是语句 setTimeout(function(){timer=setInterval(autoSwitch,1000)},1000); $imageSwitches.css('background-color','').eq(index).css('background-color','#FF3366'); //现在用到了data函数,用于图片和下表对照 if(index!=$imageShow.data('show')){ $imageShow.data('show',index); $images.hide().eq(index).fadeIn('slow'); } }) }) } //自动显示的函数 function autoSwitch(){ $nowIndex=$imageShow.data('show')+1; if($images.size()>$nowIndex){ $imageSwitches.css('background-color','').eq($nowIndex).css('background-color','#FF3366'); $imageShow.data('show',$nowIndex); $images.hide().eq($nowIndex).fadeIn('slow'); }else{ init(); } } //初始化到第一张图片开始 function init(){ $imageShow.data('show',0); $images.hide().eq(0).fadeIn('slow'); $imageSwitches.css('background-color','').eq(0).css('background-color','#FF3366'); } }); script> 1 2 3 4 5 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]