gpt4 book ai didi

javascript - Jquery 放大和缩小适用于 SCSS 而不是平滑

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:28:15 26 4
gpt4 key购买 nike

我有一张 Canvas 。我必须缩放它直到按下放大按钮并缩小它直到按下缩小按钮。我已经设法让它工作,但它有延迟。即使我松开按钮,它也会继续放大或缩小。到目前为止,这是我尝试过的。请帮我。您可以在现场查看 Here .

<script language="javascript">
var timeout, clicker = $('#zoomin'),
clicker2 = $('#zoomout');

clicker.mousedown(function() {
timeout = setInterval(function() {
var wd = $("#canvas").width();
var ht = $("#canvas").height();
wd = parseInt(wd) + 250;
ht = parseInt(ht) + 250;
$("#canvas").animate({
width: wd,
height: ht
});
var ctx = canvas.getContext("2d");
ctx.drawImage(backgroundImage, 0, 0, wd - 1, ht - 1);
ctx.drawImage(outlineImage, 0, 0, wd - 1, ht - 1);
redraw();
}, 500);

return false;
});

clicker2.mousedown(function() {
timeout = setInterval(function() {
var wd = $("#canvas").width();
var ht = $("#canvas").height();
wd = parseInt(wd) - 250;
ht = parseInt(ht) - 250;
if (wd < 500) {
return false;
}
$("#canvas").animate({
width: wd,
height: ht
});
var ctx = canvas.getContext("2d");
ctx.drawImage(backgroundImage, 0, 0, wd - 1, ht - 1);
ctx.drawImage(outlineImage, 0, 0, wd - 1, ht - 1);
redraw();
}, 500);

return false;
});

$(document).mouseup(function() {
clearInterval(timeout);
return false;
});

$("#zoomout").mousedown(function() {
var wd = $("#canvas").width();
var ht = $("#canvas").height();
wd = parseInt(wd) - 250;
ht = parseInt(ht) - 250;
if (wd < 500) {
return false;
}
$("#canvas").animate({
width: wd,
height: ht
});
var ctx = canvas.getContext("2d");
ctx.drawImage(backgroundImage, 0, 0, wd - 1, ht - 1);
ctx.drawImage(outlineImage, 0, 0, wd - 1, ht - 1);
redraw();
console.log(wd + ":" + ht);
});

$("#zoomin").click(function() {
var wd = $("#canvas").width();
var ht = $("#canvas").height();
wd = parseInt(wd) + 250;
ht = parseInt(ht) + 250;
$("#canvas").animate({
width: wd,
height: ht
});
var ctx = canvas.getContext("2d");
ctx.drawImage(backgroundImage, 0, 0, wd - 1, ht - 1);
ctx.drawImage(outlineImage, 0, 0, wd - 1, ht - 1);
redraw();
console.log(wd + ":" + ht);
});
$("#zoomout").click(function() {
var wd = $("#canvas").width();
var ht = $("#canvas").height();
wd = parseInt(wd) - 250;
ht = parseInt(ht) - 250;
if (wd < 500) {
return false;
}
$("#canvas").animate({
width: wd,
height: ht
});
var ctx = canvas.getContext("2d");
ctx.drawImage(backgroundImage, 0, 0, wd - 1, ht - 1);
ctx.drawImage(outlineImage, 0, 0, wd - 1, ht - 1);
redraw();
console.log(wd + ":" + ht);
});
</script>

最佳答案

禁用/删除您的点击处理程序。

点击事件在鼠标释放时触发。这意味着,您正在做的是,当用户释放鼠标时,您调用 jQuery 来进一步缩放 Canvas 。

如果删除点击处理程序, Canvas 在鼠标释放后不应继续动画。

关于javascript - Jquery 放大和缩小适用于 SCSS 而不是平滑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37803755/

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