我想在超时后动画div

时间:2013-06-25 15:10:53

标签: jquery

这是小提琴:http://jsfiddle.net/e5ana/9/

有5个场景,默认场景加载页面。将鼠标悬停在地图中的引脚上,然后场景发生变化。在实际网站中,黑色区域隐藏了额外的场景。

以下是其中一个场景的代码:

    $("a.dt").mouseenter(function(){
    $(".town").filter(':not(:animated)').animate({
    bottom: '0px'
  }, 500);
    $("#dt").animate({
    bottom: '126px'
  }, 500);
});

我被困的地方......

如果在十秒钟后没有任何引脚悬停,我希望任何可见的场景都可以动画下来,我希望默认场景(id =“dt”)能够生成动画。

当我将超时代码添加到每个mouseenter函数时,我接近了,但是默认场景似乎被卡住了动画。换句话说,即使它有一个“城镇”类别,在另一个引脚上的mouseenter也无法降低默认场景。

这是我正在尝试的超时代码:

var t;
var del = 10000; //Ms delay 
    $(document).mousemove(function(){
    clearTimeout(t);
    var t = setTimeout(function(){
        //If the mouse is not moved
        $(".town").animate({
            bottom: '0px'
        }, 500);
        $("#dt").animate({
            bottom: '126px'
        }, 500);
    }, del);
});

我错过了什么?

=====================

因此,正如我在下面评论的那样,消除重复的全局'var t'就可以了。谢谢!

现在我正在尝试仅在隐藏默认场景时运行代码。这是因为如果默认场景可见,则代码会运行,并且会将该场景设置为动画并再次备份。

这是我正在尝试的......

if ($('#dt').css('bottom') == '0px') {
var t;
var del = 10000; //Ms delay 
    $(document).mousemove(function(){
    clearTimeout(t);
    t = setTimeout(function(){
        //If the mouse is not moved
        $(".town").animate({
            bottom: '0px'
        }, 500);
        $("#dt").animate({
            bottom: '126px'
        }, 500);
    }, del);
});
}

但它不起作用。不会抛出脚本错误,也不会发生任何事情。

http://jsfiddle.net/webguy262/e5ana/18/

更新了小提琴

0 个答案:

没有答案