DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> jQuery 插件 將this下的div輪番顯示
jQuery 插件 將this下的div輪番顯示
編輯:JQuery特效代碼     

代碼如下:
/*
將this下的div輪番顯示
dname指定需要執行此動作的元素,如果沒有指定dname,將默認全部子元素;
tname指定與dname對應的激活元素;
speed顯示切換速度;
effe顯示的效果;
*/
(function(){
.fn.w_picSwap=function(dname,tname,speed,effe){
speed=speed || 2000;
dname=dname || "";
tname=tname || "";
effe=effe || 1;
return this.each(function(){
var myTime;
var obj=(this);
var objs=(this).find(dname);
var objnl=(this).find(tname).not(dname);
var len2=objnl.length;
var len=objs.length;
if(len<2){ return;}
var si=0;
var old=0;
objs.not(':first').css('opacity',0);
function showImg(){
old=si;si=(si==(len-1))?0:si+1;
effect(objs.eq(old),objs.eq(si));
if(len2){
objnl.eq(old).removeClass("on");
objnl.eq(si).addClass("on");
}
};
function effect(o,n){
switch(effe){
case 1:
o.stop().animate({opacity:0});
n.stop().animate({opacity:1});
break;
case 2:
var toff=o.position();
n.stop().css("top",toff.top+o.outerHeight()).animate({top:toff.top,opacity:1},200);
o.stop().animate({top:toff.top-o.outerHeight(),opacity:0});
break;
}
}
function begin(){
myTime = setInterval(showImg,speed);
};
objnl.mouseover(function(){
si=objnl.index(this);
showImg();
});
//滑入 停止動畫,滑出開始動畫.
obj.hover(function(){
if(myTime){clearInterval(myTime);}
},function(){
begin();
});
begin();
});
};
})(jQuery);

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved