jQuery动画延迟添加类

Gar*_*eth 7 jquery animation

我试图使用jquery延迟添加类.所有的代码工作正常,但我想延迟.addClass('hideText')直到悬停功能完成后有人告诉我该怎么做呢?

这是代码:

$(document).ready(function() {

$('.listing div').addClass('hideText');

$('.listing div').hover(

function() {
    $(this)
    .stop(true)
    .removeClass('hideText')
    .animate(
        {top: '0'},
        {duration: 300, easing: 'linear', queue: false}
    )
    },
    function() {
        $(this)
        .stop(true)
        .animate(
            {top: '150px'},
            {duration: 300, easing: 'linear', queue: false}
        )
        .addClass('hideText')
    });
Run Code Online (Sandbox Code Playgroud)

});

Int*_*ang 2

将该.addClass()行放在回调中:

$(document).ready(function() {

$('.listing div').addClass('hideText');

$('.listing div').hover(

function() {
    $(this)
    .stop(true)
    .removeClass('hideText')
    .animate(
        {top: '0'},
        {duration: 300, easing: 'linear', queue: false}
    )
    },
    function() {
        $(this)
        .stop(true)
        .animate(
            {top: '150px'},
            {duration: 300, easing: 'linear', queue: false},
            function() {
                 $(this).addClass('hideText');
            }
        );
    });
});
Run Code Online (Sandbox Code Playgroud)