jQuery中的不透明循环

jQuery中的不透明循环,jquery,animation,opacity,Jquery,Animation,Opacity,我在一个堆栈中有两个图像,比如a和b。b的不透明度为1,我希望当我将鼠标悬停在它上面时,它将开始设置不透明度从0到1以及从1到0的动画。这样,这个循环将一直持续到鼠标离开图像为止 你可以在这里找到类似的东西: 我是jQuery新手。var cancel=false; var cancel = false; $("#b").hover(function() { var fadeDirection = 0; var next = function(jqo) { i

我在一个堆栈中有两个图像,比如a和b。b的不透明度为1,我希望当我将鼠标悬停在它上面时,它将开始设置不透明度从0到1以及从1到0的动画。这样,这个循环将一直持续到鼠标离开图像为止

你可以在这里找到类似的东西:

我是jQuery新手。

var cancel=false;
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;
});
$(“#b”).hover(函数(){ var fadeDirection=0; var next=功能(jqo){ 如果(取消){ jqo.stop(真);
jqo.fadeIn();//向我们展示到目前为止您所拥有的代码。演示之类的工具将非常有用。