我已生成jQuery动画图像。第二次单击时,动画jQuery无法工作
问题是第一次j query animate正常工作时,我隐藏了图像,然后单击第三次单击按钮,我想和第一次一样设置动画,但速度更快,工作不正常 动画结束前单击按钮导致的速度问题。通过在单击按钮时禁用按钮,然后在动画完成后重新启用按钮,可以防止出现这种情况。此外,如果在每个动画完成后重置样式,效果会更好。您可以查看下面的代码我已生成jQuery动画图像。第二次单击时,动画jQuery无法工作,jquery,html,css,animation,Jquery,Html,Css,Animation,问题是第一次j query animate正常工作时,我隐藏了图像,然后单击第三次单击按钮,我想和第一次一样设置动画,但速度更快,工作不正常 动画结束前单击按钮导致的速度问题。通过在单击按钮时禁用按钮,然后在动画完成后重新启用按钮,可以防止出现这种情况。此外,如果在每个动画完成后重置样式,效果会更好。您可以查看下面的代码 $( "#btn1" ).click(function() { var $this = $(this); var clickCount = ($this.dat
$( "#btn1" ).click(function() {
var $this = $(this);
var clickCount = ($this.data("click-count") || 0) + 1;
$this.data("click-count", clickCount);
if (clickCount%2 == 0) {
$("#img1").hide('clip').animate({
marginLeft: "40%"
},1500);
} else {
$("#img1").show('clip').animate({
marginLeft: "40%"
},1500);
}
});
}))
动画结束前单击按钮导致的速度问题。通过在单击按钮时禁用按钮,然后在动画完成后重新启用按钮,可以防止出现这种情况。此外,如果在每个动画完成后重置样式,效果会更好。您可以查看下面的代码
$( "#btn1" ).click(function() {
var $this = $(this);
var clickCount = ($this.data("click-count") || 0) + 1;
$this.data("click-count", clickCount);
if (clickCount%2 == 0) {
$("#img1").hide('clip').animate({
marginLeft: "40%"
},1500);
} else {
$("#img1").show('clip').animate({
marginLeft: "40%"
},1500);
}
});
})) 试试你的小提琴。它起作用了
$("#btn1").click(function() {
var button = $(this);
button.attr("disabled", true);
var $this = $(this);
var clickCount = ($this.data("click-count") || 0) + 1;
$this.data("click-count", clickCount);
if (clickCount % 2 == 0) {
$("#img1").hide('clip').animate({
marginLeft: "40%"
}, 1500).promise().then(function() {
button.removeAttr("disabled");
});
} else {
$("#img1").removeAttr('style');
$("#img1").show('clip').animate({
marginLeft: "40%"
}, 1500).promise().then(function() {
button.removeAttr("disabled")
});
}
用小提琴试试这个。它起作用了
$("#btn1").click(function() {
var button = $(this);
button.attr("disabled", true);
var $this = $(this);
var clickCount = ($this.data("click-count") || 0) + 1;
$this.data("click-count", clickCount);
if (clickCount % 2 == 0) {
$("#img1").hide('clip').animate({
marginLeft: "40%"
}, 1500).promise().then(function() {
button.removeAttr("disabled");
});
} else {
$("#img1").removeAttr('style');
$("#img1").show('clip').animate({
marginLeft: "40%"
}, 1500).promise().then(function() {
button.removeAttr("disabled")
});
}
试试这个
试试这个
你的工作。你的动画速度很快。因此,您必须增加动画的时间
if (clickCount%2 == 0) {
$("#img1").hide('clip').animate({
marginLeft: "0%"
});
}
else
{
$("#img1").show('clip').animate({
marginLeft: "40%"
});
你的工作。你的动画速度很快。因此,您必须增加动画的时间
if (clickCount%2 == 0) {
$("#img1").hide('clip').animate({
marginLeft: "0%"
});
}
else
{
$("#img1").show('clip').animate({
marginLeft: "40%"
});
工作示例:将html和js放在fiddle的不同部分。在动画完成之前单击按钮。可以在动画运行时禁用该按钮,并在动画完成后启用它。你们可以通过工作演示看到我的答案工作示例:将你们的html和js放在fiddle的不同部分。你们在动画完成之前点击按钮。可以在动画运行时禁用该按钮,并在动画完成后启用它。您可以通过工作演示看到我的答案工作演示:-嘿,Huseyin BABAL在此演示中在桌面上工作正常,但在移动设备中拖动放大镜不起作用。帮助me@MohsinKureshi你能就那个问题再提一个问题吗?Thanks@BABAL我做了,但我没有得到该工作演示的解决方案:-嘿,Huseyin BABAL在该演示中在桌面上工作正常,但在移动设备中拖动放大镜不起作用。帮助me@MohsinKureshi你能就那个问题再提一个问题吗?Thanks@BABAL我做了,但我没有得到工作演示的解决方案:-jsfiddle.net/mohsin80/4ww8efx5/2 hey-Man程序员在这个演示中在桌面上工作很好,但在移动设备上拖动放大镜不起作用。帮助我工作演示:-jsfiddle.net/mohsin80/4ww8efx5/2 hey-Man程序员在这个演示中在桌面上工作很好,但在移动设备上拖动放大镜坏了,帮帮我