-1

I'm building a webpage with many moving graphic/text elements using javascript, I'm using div for each element but on my mobile phone it is slow. Is there tips for making it faster ? For exemple if my container div overflow style is set to hidden it is faster.

Also is it better to use SVG or something else ?

Entretoize
  • 2,124
  • 3
  • 23
  • 44

1 Answers1

0

Handling DOM elements is a heavy thing to do, even on desktop browsers, and it is also inefficient. But there are good libraries out there to work with DOM elements, such as animating them, moving them, styling them programmatically, etc ... . For example JQuery makes it easier and more robust across different platforms/browsers combination. But The problem of slowness is with DOM itself, not the JS and not the code you write and how you handle it.

So You're right! You're better using something else than the DOM, SVG makes things a little better. I honestly do not know much about it and every time I see it's syntax, its just frightening! But I know it has it's own animating system and that's more lightweight that other DOM elements.

But what I suggest to you is canvas. It is HTML5, faster, and its syntax is much more beautiful, than handling DOM elements (i.e. div) and drawing SVG (i.e. 80 M 62.5 D 10). Canvas uses beautiful JS function APIs and is logically easy to understand and design. All you do is pureJS. Also canvas's performance has proven to be great! for example : https://robostorm.io/

It gives the beautyness and functionality of Adobe Flash, but portabality of JS : )

Ardeshir Izadi
  • 955
  • 1
  • 7
  • 25