在动画过程中禁用单击
disable click during animation
我想在动画过程中禁用对元素的单击,当动画结束时,再次启用它。 这是代码:
$(document).on('click touchstart', '.slot1-up', function(e){
e.preventDefault();
firstSlotPos = parseInt($(".jSlots-wrapper:nth-child(1) .slot").css('top'));
console.log(firstSlotPos)
if (firstSlotPos < -309) {
$(".jSlots-wrapper:nth-child(1) .slot").stop(true,true).animate( { 'top' : firstSlotPos + 310 + "px" },600, 'easeInOutSine', function() {
});
}
});
您可能会使用
off
/on
动态添加/删除事件钩子,但这可能会变得混乱。
我的首选方法是在元素上存储一个data
属性,以显示其状态。由此,您可以确定是否允许执行处理程序函数。像这样:
$(document).on('click touchstart', '.slot1-up', function(e){
e.preventDefault();
var $el = $(this);
if (!$el.data('animating')) {
var $slot = $(".jSlots-wrapper:nth-child(1) .slot");
$el.data('animating', true);
firstSlotPos = parseInt($slot.css('top'));
if (firstSlotPos < -309) {
$slot.stop(true,true).animate({ 'top' : (firstSlotPos + 310) + "px" }, 600, 'easeInOutSine', function() {
$el.data('animating', false);
});
}
}
});
只需使用伪选择器检查它:animated:
$(document).on('click touchstart', '.slot1-up', function (e) {
e.preventDefault();
// if animated, return {undefined}
if($(".jSlots-wrapper:nth-child(1) .slot").is(':animated')) return;
firstSlotPos = parseInt($(".jSlots-wrapper:nth-child(1) .slot").css('top'));
if (firstSlotPos < -309) {
$(".jSlots-wrapper:nth-child(1) .slot").stop(true, true).animate({
'top': firstSlotPos + 310 + "px"
}, 600, 'easeInOutSine', function () {
});
}
});
相关文章:
- 使用单击函数中的jQuery切换元素
- 单击事件中的ajax请求后重定向
- 在单击事件中,第一次单击时激发代码一次,其余代码在所有单击时运行
- 如何防止用户使用javascript或jquery在链接中单击鼠标中键
- 单击angularjs中的另一个控制器时重新加载控制器
- 如果单击画布中的图像,则发出警报
- 通过动态创建数组名称在单击函数中引用 javascript 数组
- 使用 JQuery 在单击表中的 tr 时创建弹出窗口
- 单击列表中的引导输入按钮将禁用其他按钮
- this.offset不是单击函数中的函数
- 为什么不是't单击事件中返回的数组的总和
- 如何根据单击块中的哪个项目来渲染不同版本的分部
- 仅单击一行中的一个项目
- 如何通过单击javascript中的按钮来修改输入数字字段
- 单击页面中的任何按钮时,使用Jquery file Upload时都会打开文件对话框
- 如何通过单击HTML中的按钮关闭当前选项卡
- 如何在单击事件中追加数据来自数据表
- 表单操作过程中出现后退按钮问题
- 通过单击Javascript中的nextdate按钮,可以增加日期、日期、月份和年份
- 单击javascript中的按钮运行python脚本