如何解决jQuery 在 debounce 方法执行前调用动画
我有一段代码如下:
$('.cardButton').click($.debounce(1500,function () {
console.log("OK");
}));
这种情况下的去抖动效果非常好..
但是 - 我需要添加动画功能来在去抖动发生之前替换“.cardButton”元素......
做这样的事情:
$('.cardButton').click($.debounce(1500,function () {
StartAnimationLoader();
console.log("OK");
}));
// In this case - animation starts as soon as console writes out "OK" ...
或者像下面这样:
$('.cardButton').click(function(){
StartAnimationLoader();
$.debounce(1500,function () {
console.log("OK");
})
});
// When I execute code like this - there is nothing written in the console... - thus this method doesn't works
我需要在去抖动发生之前执行动画...
我在这里做错了什么?
有人可以帮我吗?
解决方法
向同一元素添加第二个(或更多)事件处理程序将触发两个事件(除非停止),因此您可以通过拥有两个单独的事件处理程序来创建两个操作:
// existing debounce fire only after user stops clicking
$('.cardButton').click($.debounce... );
// additional event will fire on every click
$(".cardButton").click(function() { StartAnimationloader() });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。