Прекратить эффект затухания jquery при наведении - PullRequest
1 голос
/ 10 марта 2012

Я пытаюсь создать этот эффект там, где div постепенно исчезают и исчезают. Хитрость заключается в том, что мне нужно, чтобы эти эффекты fadeIn и fadeOut прекратились при наведении.

Прямо сейчас этот код, который у меня есть, не останавливает все быстрое исчезновение. Что мне нужно, это переопределить? Это вообще возможно?

function animate() {
    $("#bill-items-one").fadeIn(3000);

    one = setInterval(function(){
        $("#bill-items-one").fadeOut(3000);
        $("#bill-items-one").fadeIn(3000);
    }, 6000)

    two = setInterval(function(){
        $("#bill-items-two").fadeIn(3000);
        $("#bill-items-two").fadeOut(3500);
    }, 6500)

    three = setInterval(function(){
        $("#bill-items-three").fadeIn(2000);
        $("#bill-items-three").fadeOut(4000);
    }, 6000)

    four = setInterval(function(){
        $("#bill-items-four").fadeIn(3500);
        $("#bill-items-four").fadeOut(3000);
    }, 6500)
}

animate();

$(".bill-area").hover(
    function(){
        clearInterval(one);
        clearInterval(two);
        clearInterval(three);
        clearInterval(four);
        $(".bill-item").fadeOut("fast");
    },
    function(){
        animate();
    }
);

Смотрите также эту ссылку: http://jsfiddle.net/bKKE6/

Ответы [ 3 ]

3 голосов
/ 10 марта 2012

http://api.jquery.com/stop/

$(".bill-item").stop().fadeOut("fast");
2 голосов
/ 10 марта 2012

Вам нужно stop [документы] :

$(".bill-area").hover(
    function(){
        $(".bill-item").stop(true, true).fadeOut("fast");
    },
    function(){
        animate();
    }
);

См. Демонстрацию

1 голос
/ 10 марта 2012

Используйте jQuery's .stop(), чтобы остановить анимацию.

http://api.jquery.com/stop/

...