Drawing A Svg File On A Html5 Canvas At A Specific Time
I found the topic Drawing an SVG file on a HTML5 canvas about rendering SVG. Is there a way to draw SVG animated file at specific moment of time? I mean, how to change the code var
Solution 1:
You can simply use setTimeout
to defer the insertion of the square, in this fashion :
var delayInMilliseconds = 3000;
img.onload = function() {
setTimeout(function() {
// This will happend 3 seconds after page load
ctx.drawImage(img, 0, 0);
}, delayInMilliseconds);
}
img.src = "http://upload.wikimedia.org/wikipedia/commons/d/d2/Svg_example_square.svg";
In case you want to be able to specify a date and time for the event, use a custom function to count the time left to the target date :
functiongetTimeTo(date) {
var time = date.getTime() - Date.now();
returntime;
}
And replace delayInMilliseconds
with getTimeTo(targetDate)
. See this fiddle for experimenting.
Post a Comment for "Drawing A Svg File On A Html5 Canvas At A Specific Time"