且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery在鼠标悬停时停止动画

更新时间:2023-01-25 17:47:07

如果我理解正确(我可能不太了解),则需要这样的东西:

If I'm understanding correctly (which I'm probably not), you want something like this:

var alerttimer, alertBox = $('#alert');
function resetTimeout() {
        if (alerttimer) {
                clearTimeout(alerttimer);
        }
        alerttimer = setTimeout(function() {
                alertBox.trigger('click');
        }, 5000);
}
$(function () {
        if(alertBox.length) {
                resetTimeout();
                alertBox.animate({ height: alertBox.css('line-height') || '50px' }, 200).click(function () {
                        window.clearTimeout(alerttimer);
                        alertBox.animate({ height: '0px' }, 200);
                }).mouseover(function () {
                        clearTimeout(alerttimer);
                }).mouseout(function () {
                        resetTimeout();
                });
        }
});

请务必注意,以上内容未经测试.

It's important to note that the above is very much untested.