blockly > WorkspaceSvg > scrollX

WorkspaceSvg.scrollX property

Current horizontal scrolling offset in pixel units, relative to the workspace origin.

It is useful to think about a view, and a canvas moving beneath that view. As the canvas moves right, this value becomes more positive, and the view is now "seeing" the left side of the canvas. As the canvas moves left, this value becomes more negative, and the view is now "seeing" the right side of the canvas.

The confusing thing about this value is that it does not, and must not include the absoluteLeft offset. This is because it is used to calculate the viewLeft value.

The viewLeft is relative to the workspace origin (although in pixel units). The workspace origin is the top-left corner of the workspace (at least when it is enabled). It is shifted from the top-left of the blocklyDiv so as not to be beneath the toolbox.

When the workspace is enabled the viewLeft and workspace origin are at the same X location. As the canvas slides towards the right beneath the view this value (scrollX) becomes more positive, and the viewLeft becomes more negative relative to the workspace origin (imagine the workspace origin as a dot on the canvas sliding to the right as the canvas moves).

So if the scrollX were to include the absoluteLeft this would in a way "unshift" the workspace origin. This means that the viewLeft would be representing the left edge of the blocklyDiv, rather than the left edge of the workspace.

Signature:

scrollX: number;