Stay organized with collections
Save and categorize content based on your preferences.
blockly > WorkspaceSvg > scrollY
Current vertical 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 down, this value becomes more positive, and the view is now "seeing" the upper part of the canvas. As the canvas moves up, this value becomes more negative, and the view is "seeing" the lower part of the canvas.
This confusing thing about this value is that it does not, and must not include the absoluteTop offset. This is because it is used to calculate the viewTop value.
The viewTop 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 viewTop and workspace origin are at the same Y location. As the canvas slides towards the bottom this value (scrollY) becomes more positive, and the viewTop becomes more negative relative to the workspace origin (image in the workspace origin as a dot on the canvas sliding downwards as the canvas moves).
So if the scrollY were to include the absoluteTop this would in a way "unshift" the workspace origin. This means that the viewTop would be representing the top edge of the blocklyDiv, rather than the top edge of the workspace.
Signature:
scrollY: number;
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-18 UTC."],[[["`scrollY` represents the vertical scroll offset of the workspace canvas in pixels, relative to the workspace origin."],["Positive `scrollY` values indicate the canvas has moved down, revealing the upper part; negative values indicate upward movement, revealing the lower part."],["`scrollY` does not include the `absoluteTop` offset, ensuring `viewTop` remains relative to the workspace origin and not the `blocklyDiv`."],["The workspace origin, the top-left corner of the workspace, is the reference point for both `scrollY` and `viewTop` calculations."],["As the canvas scrolls, `scrollY` and `viewTop` change to reflect the relative positions of the canvas and the visible area within the workspace."]]],[]]