3 ms·
The previous function only works for Chrome, these one works for Chrome, FF, and Safari function animateLine(elem) { var offset = 0 elem.style.strok
by efortis 5y ago
The previous function only works for Chrome, these one works for Chrome, FF,
and Safari
function animateLine(elem) {
var offset = 0
elem.style.strokeDasharray = '6 1'
elem.style.strokeDashoffset = offset;
requestAnimationFrame(anim)
function anim() {
offset -= 0.2
elem.style.strokeDashoffset = offset
requestAnimationFrame(anim)
}
}
- linkdd 5y agoThanks, For me Inkscape is insanely hard to use, I ended up using a canvas and drawing directly in it. The 2D context API provides the `lineDashOffset` property as well, so it works fine :)
- efortis 5y agoNice, what'd you use for drawing it?
- linkdd 5y agoVanilla JS API: <canvas id="my-canvas"></canvas> <div style="display: none;"> <img id="asset-foo" src="/img/foo.svg" /> <!-- ... --> </div> <script defer type="application/javascript"> window.addEventListener("DOMContentLoaded", () => { const canvas = document.getElementById("my-canvas") const context = canvas.getContext("2d") const fooAsset = document.getElementById("asset-foo") // ... const frame = () => { canvas.clearRect(0, 0, canvas.width, canvas.height) // NB: this will fail if image could not be loaded by the browser context.drawImage(fooAsset, x, y, w, h) // ... requestAnimationFrame(frame) } requestAnimationFrame(frame) }) </script> The result can be seen here: http://bd2e-77-141-81-91.ngrok.io http://bd2e-77-141-81-91.ngrok.io (I'll shut down the ngrok in a few hours)