How do i insert an image and animate it using web? will it be possible? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

How do i insert an image and animate it using web? will it be possible?

18th Jul 2018, 1:32 AM
SK Sai
SK Sai - avatar
6 Answers
+ 3
Do it like this: drawImage(element, x, y); The x is how many pixels from the left, and the y from the top. You can’t put the URL for element, as it actually needs to be an <img> element: <img src = “SomeURL” id = “image”/> <canvas></canvas> <script> let ctx = document.getElementsByTagName(“canvas”)[0].getContext(“2d”); let image = document.getElementById(“image”); ctx.drawImage(image, 50, 50); </script> Hope that helps!
18th Jul 2018, 6:19 AM
Rowsej
Rowsej - avatar
+ 6
thanks
19th Jul 2018, 1:21 AM
SK Sai
SK Sai - avatar
+ 5
Use sprites to form the sequential frames, enable them one after another.. https://code.sololearn.com/WFrv82FuZwg2/?ref=app
18th Jul 2018, 3:53 AM
Calviղ
Calviղ - avatar
+ 1
yes its possible
18th Jul 2018, 1:56 AM
Nura Programmer
Nura Programmer - avatar
18th Jul 2018, 1:59 AM
Nura Programmer
Nura Programmer - avatar
+ 1
You can use the drawImage( ) method. https://www.w3schools.com/tags/canvas_drawimage.asp And yes, animation is also possible. Have a look at this: https://code.sololearn.com/WmP6CuzCPFta/?ref=app
18th Jul 2018, 3:02 AM
777
777 - avatar