2011-09-09 37 views
0

我在堆栈中有两个图像,分别是#a和#b。 b的不透明度为1,当我将鼠标悬停在它上面时,它会启动不透明度的动画从0到1,并且比1到0 ...以这种方式,此循环将继续,直到鼠标离开图像。你可以在这里找到类似的东西: http://www.myhabit.com/#page=b&dept=women&sale=A3RT7N8JLFHTE3&ref=qd_g_cur_img_bjQuery中的不透明循环

我是jQuery中的新人,从几个小时我的头撞。请帮忙。

+2

向我们展示您迄今为止的代码。一个[SSCCE](http://sscce.org)如http://jsfiddle.net演示将非常有用。 –

回答

1
var cancel = false; 

$("#b").hover(function() { 
    var fadeDirection = 0; 

    var next = function(jqo) { 
     if(cancel) { 
      jqo.stop(true); 
      jqo.fadeIn(); // <-- not the neatest but I don't know another way to make it compatible 
      jqo.stop(false, true); 
     } 

     if(fadeDirection = 1 - fadeDirection) { 
      jqo.fadeIn(function() { next(jqo); }); 
     } else { 
      jqo.fadeOut(function() { next(jqo); }); 
     } 
    }; 

    next($(this)); 
}, function() { 
    cancel = true; 
}); 

这样的事情?