滑動說明文字 .slide_bg{border:#999999 3px solid;width:207px;height:106px;position:relative;overflow:hidden;float:left;margin-right:16px;margin-top:26px;} .slide_img{background-image:url(/jscss/demoimg/wall1.jpg);width:207px;height:106px;} .slide_txt{width:197px;height:100px;background-color:#000000;position:absolute;top:106px;left:0px;color:#FFCC33;line-height:22px;padding:5px;font-size:12px;} 春天:春天是播種的季節。 夏天:夏天是火熱的季節。 秋天:秋天是豐收的季節。 冬天:冬天是雷人的季節。 [Ctrl A 全選 註:如需引入外部Js需刷新才能執行] var slide_content=function(){ var id="slide_content" //滑动图片父容器的id名 var interval=10; //滑动速度 var interval2=100; //文字滑出延迟时间(毫秒) var interval3=500; //文字内容自动消失的延迟时间(毫秒) var opacity=69; //文字内容图层透明度 var timer2=new Array(); var elem=new Array(); var status=new Array(); var div=document.getElementById(id).getElementsByTagName("div"); var timer3=0; //run_animation var d=function(){ var timer,obj,txt;var ypos=100; this.run=function(pra1,pra2,dir){obj=pra1;txt=pra2;if(dir>0){clearTimeout(timer);clearTimeout(timer3);timer3=setTimeout(obj.up,interval2);}else{clearTimeout(timer);obj.down()};txt.style.filter="alpha(opacity="+opacity+")";txt.style.opacity=opacity/100;} //向上滑动 this.up=function(){if(ypos<=0){txt.style.top="0px"}else{ypos-=10;txt.style.top=ypos+"px";timer=setTimeout(obj.up,interval)}} //向下滑动 this.down=function(){if(ypos>=106){txt.style.top="106px";}else{ypos+=15;txt.style.top=ypos+"px";timer=setTimeout(obj.down,interval)}} } //init mouse_behavior for(var i=0;i<div.length;i+=3){ div[i+1].index=div[i+2].index=i+2; elem[i+2]=new d(); div[i+1].onmouseover=function(){elem[this.index].run(elem[this.index],div[this.index],1)}; div[i+1].onmouseout=function(){var n=this.index;if(status[n]!=1){timer2[n]=setTimeout(imgout,interval3)};function imgout(){elem[n].run(elem[n],div[n],-1)}} div[i+2].onmouseout=function(){elem[this.index].run(elem[this.index],div[this.index],-1);status[this.index]=0} div[i+2].onmouseover=function(){clearTimeout(timer2[this.index]);status[this.index]=1} } } //网页加载完毕时,启动函数 window.onload=slide_content;