[英]Jquery/javascript reset html to previous form after calling javascript function
So basically I've created a function which animates a green check sign after a user clicks on button... The thing is I need need to revert the HTML to the old form once the onclick event is done in jquery post like this: 因此,基本上,我创建了一个在用户单击按钮后为绿色复选标记设置动画的函数...问题是,一旦在jquery帖子中完成了onclick事件,我需要将HTML还原为旧格式,如下所示:
$.post("/User/SaveWatchList", postData)
.done(function (response) {
if (response == "AllFieldsRequired") {
ShowErrorMessage("All fields are required!");
return;
} else {
AnimateGreenCheck();
}
});
Please note the function called AnimateGreenCheck, which looks like following: 请注意名为AnimateGreenCheck的函数,该函数如下所示:
function AnimateGreenCheck() {
var start = 100;
var mid = 145;
var end = 250;
var width = 20;
var leftX = start;
var leftY = start;
var rightX = mid - (width / 2.7);
var rightY = mid + (width / 2.7);
var animationSpeed = 20;
var ctx = document.getElementsByTagName('canvas')[0].getContext('2d');
ctx.lineWidth = width;
ctx.strokeStyle = 'rgba(0, 150, 0, 1)';
for (i = start; i < mid; i++) {
var drawLeft = window.setTimeout(function () {
ctx.beginPath();
ctx.moveTo(start, start);
ctx.lineTo(leftX, leftY);
ctx.stroke();
leftX++;
leftY++;
}, 1 + (i * animationSpeed) / 3);
}
for (i = mid; i < end; i++) {
var drawRight = window.setTimeout(function () {
ctx.beginPath();
ctx.moveTo(leftX, leftY);
ctx.lineTo(rightX, rightY);
ctx.stroke();
rightX++;
rightY--;
}, 1 + (i * animationSpeed) / 3);
}
}
And this is the "canvas" element on which it draws the green check sign: 这是在其上绘制绿色复选标记的“画布”元素:
<div style="width:100%; text-align:center;">
<canvas class="canvas" height="160"></canvas>
</div>
I need to somehow repeat his process of drawing each time the user clicks the button and when the post is done... 每当用户单击按钮以及完成发布后,我都需要以某种方式重复他的绘制过程...
How could I do this? 我该怎么办?
Okay so this did it : 好的,这样做了:
var canvas = $('.canvas')[0]; // or document.getElementById('canvas');
canvas.width = canvas.width;
as described in the specifications: 如规格中所述:
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.