[whatwg] Supporting scrollTop and scrollLeft on the Canvas element

Charles Pritchard chuck at jumis.com
Tue Jan 31 14:35:45 PST 2012

Floating a proposal here:

I'd like to see scrollTop and scrollLeft supported for the Canvas 
element. They would simply fire an onscroll event on the element, and do 
nothing else.
Many Canvas UIs use only one visible canvas layer, or otherwise, one 
main canvas layer.

It'd be quite handy to be able to use the scrollTop and scrollLeft 
setters, and as an author, hook into canvas.onscroll to identify when 
updates ought to be painted.

Currently, authors can create a large canvas, and place it in a div:
<div style="overflow: hidden">
<canvas>This can is larger than the div</canvas>

It would be great to be able to respond to scroll events, such as 
Element.scrollIntoViewIfNeeded and/or ctx.scrollPathIntoView,
and simplify the model in the future.

<canvas onscroll="repaint(scrollLeft,scrollTop)">This canvas is the same 
size as the div and responds to onscroll</canvas>

The values for scrollLeft and scrollTop would be in css pixels, as they 
are for other elements, and when set, they would trigger an onscroll 
event, as usual.


More information about the whatwg mailing list