jquery等待。设置动画,然后转到锚定位置
我正在使用jquery animate将div滑离页面,这很好,但我想将动画更改为:jquery等待。设置动画,然后转到锚定位置,jquery,jquery-animate,Jquery,Jquery Animate,我正在使用jquery animate将div滑离页面,这很好,但我想将动画更改为: 只发生一次(因为如果有人双击它,div就会返回),并且 等待动画完成,然后按href键 这是执行div幻灯片的代码: $(".choose").click(function(event) { var $contentDiv = $("#content"); $contentDiv.stop().animate({ marginLeft: parseInt($contentDiv
$(".choose").click(function(event) {
var $contentDiv = $("#content");
$contentDiv.stop().animate({
marginLeft: parseInt($contentDiv.css('marginLeft'),10) == 0 ?
$contentDiv.outerWidth() : 0
});
});
您可以调用
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();
});
这就是我想要的,我一直在用event.prenetDefault绕圈子,但它没有像我那样工作,哈哈。谢谢