Use the canvas tag or create a bunch of <div's> Which is faster?
Hi I have an array of hex colors and for each color in the array I want to create an 80px by 80px square representing that color. Which will be faster to use?
1: Use the canvas tag, iterate over the array, and use fillStyle and fillRect ();
or
2: Iterating over the array and creating a div box and setting the background color of the div to the current color in the array.
Note. I have 1034 colors and I am opening other suggestions, but it must be network based and cannot be flash.
a source to share
I would personally go to canvas (excanvas.js for VML emulation in IE will do the job). For simplicity and future code extension reasons.
The problem is browsers with built-in canvas implementation will perform better with 1st option, IE should be faster using DIVs (2nd method). This is due to the practice of emulation, which creates VML elements on the fly (there are simply more elements to create than just DIVs).
It's just a guess though :), write some tests and compare.
a source to share