On a semi-modern + computer with a semi-recent + browser, the fastest thing to do is probably take a super-long div with background images, set the overflow to hidden and scroll by editing the scrollLeft or scrollTop properties. This is much faster than adjusting CSS properties, as it should not invoke recalculation calculations in the CSS engine. Basically, whenever you touch on the DOM property, which can be affected by CSS, the whole structure (or at least a lot) of the structure of the document needs to be re-checked and re-rendered.
You can load chunks of background as they get closer to avoid a giant huge image load. I don’t believe that there is a 100% sure way to get an image out of memory in browsers, but deleting links to it in the DOM or in your CSS will probably not hurt when you scroll far enough past part of your background. Thus, the browser garbage collector, at least, has the ability to clear memory.
In mobile solutions that rely on webviews (for example, Cordova / Phonegap) , however, it’s good why I came to this question.
I have no idea, but I'm sure mixing HTML and canvas is a disgusting idea for performance. Right now I have a non-super-complicated android game, choking on 50x50 100px tiles in the canvas element in the Android web view, which also has some basic HTML code in elements such as controls, and highlighting a couple of others canvas elements from rest. I basically have a bird-eye ship traveling around and scanning with a crappy radiation circle that shows elements on a map of the war nebula. Works great in a browser. A complete disaster in the version of the cordova application.
I suspect that the only way I'm going to implement my mobile game is to use one of the many openGL-wrap-in-a-canvas-API solutions and completely align the HTML, which I find damn convenient for implementing the user interface, given that the bulk of my experience is with the web interface. Another general tip for the HTML representation of web pages is to avoid scrolling inside the internal elements if you can (so just let the body handle the overflow). Overflow scrolling in everything except the body didn't even work in Android 2 web browsers, and it still seemed like this was causing 4.1 views to be throttled in an earlier / simpler version of the application I'm working on.
source share