gpt4 book ai didi

jquery等待.animate然后转到 anchor 位置

转载 作者:行者123 更新时间:2023-12-01 08:25:59 25 4
gpt4 key购买 nike

我正在使用 jquery animate 将 div 滑出页面,这工作正常,但我想将 animate 更改为:

  1. 只发生一次(因为如果有人双击它,div 就会回来),并且
  2. 等待动画完成,然后再执行 href。

这是执行 div 幻灯片的代码:

$(".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();
});

关于jquery等待.animate然后转到 anchor 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3815425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com