I have an experimental problem. I want to make an image with a lot of div 's, divs have 1px width and height . I got the image pixel data from the canvas context , create a div and gave a value for each div background-color , this means that the div count is equal to the number of pixels in the image, but if there is an image, for example, with a resolution of 100x56, this is normal, but in case, if it is more, the browser makes html very slow. Code piece below
var fragment = document.createDocumentFragment(); var data = context.getImageData(0, 0, canvas.width, canvas.height).data; for (var i = 0; i < data.length; i += 4) { var red = data[i]; var green = data[i + 1]; var blue = data[i + 2]; var div = document.createElement('div'); div.style.width = '1px'; div.style.height = '1px'; div.style.float='left' div.style.backgroundColor = 'rgb(' + red + ',' + green + ',' + blue + ')'; fragment.appendChild(div); } cnt.appendChild(fragment)
I know this problem is not applicable so much, but I want to know if there is any case to make many elements faster in the browser (I use Chrome) or is it browser independent?
Ps: My colleague said: “There is no such problem in Silverlight, you can even add 50,000 elements and it will work fine”, and I want to give it “my answer”
thanks
source share