I have a canvas. I have to zoom in and out until the zoom button is pressed and down until the zoom out button is pressed. I managed to get it to work, but it works with delays. and it continues to zoom in or out even when I released the button. This is what I have tried so far. Please help me. You can check it out on the website 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>