2010-09-28 60 views
1

我使用jQuery动画滑动一个div关闭页面,在此工作正常,但我想改变动画到:jQuery的等待.animate然后去锚点位置

  1. 只发生一次(因为如果有人双击它,div会回来),并且在href被跟踪之前等待动画完成。

这是执行DIV幻灯片代码:

$(".choose").click(function(event) { 
    var $contentDiv = $("#content"); 

    $contentDiv.stop().animate({ 
     marginLeft: parseInt($contentDiv.css('marginLeft'),10) == 0 ? 
     $contentDiv.outerWidth() : 0 
    }); 
}); 

回答

3

您可以拨打event.preventDefault()防止默认点击动作,然后用回调动画之后设置location.href执行手动重定向。 ..

$(".choose").click(function(event) { 
    var $contentDiv = $("#content"); 
    var redir = $(this).attr("href"); 

    $contentDiv.stop().animate({ 
     marginLeft: parseInt($contentDiv.css('marginLeft'),10) == 0 ? 
     $contentDiv.outerWidth() : 0 
    }, function() { location.href = redir; }); 

    event.preventDefault(); 
}); 
+0

这就是我想要的,我一直在event.prenetDefault周围跳动,但它没有工作,我做到了这一点哈哈。谢谢 – slexAtrukov 2010-09-28 17:41:16