0

以下代码在执行悬停功能时扩展了 DIV 的高度,如果将鼠标放置 5 秒,我如何更改代码以便必须执行该功能。另外我怎样才能减慢滑动速度?

$(document).ready(function () {
    $("#myhead").hover(

    function () {
        $(this).animate({
            height: '+=250'
        }, '1000');
    }, function () {
        $(this).animate({
            height: '-=250px'
        }, '1000');
    });
});
4

2 回答 2

2

您可以将此插件用于基于时间的悬停http://cherne.net/brian/resources/jquery.hoverIntent.html

此插件在特定超时后调用 mousein 和 mouseout 函数。您可以通过以下方式降低滑动速度

$(document).ready(function () {
$("#myhead").hover(

function () {
    $(this).animate({
        height: '+=50',
    }, {duration:2000});
}, function () {
    $(this).animate({
        height: '-=50px'
    }, {duration:2000});
});

});

于 2012-01-22T16:21:11.643 回答
1

有一个名为“hoverintent”的 jQuery 插件,它允许您编写具有“超时”属性的悬停函数,该属性可以执行您所描述的操作。

http://archive.plugins.jquery.com/project/hoverIntent

可以通过增加动画后的数字来减慢动画的速度——在您当前的代码中,它是“1000”。以毫秒为单位,因此 1000 等于 1 秒。

于 2012-01-22T16:19:29.210 回答