Blockly. Scrollbar
Constructor
Scrollbar
new Scrollbar(workspace, horizontal, opt_pair, opt_class)
Class for a pure SVG scrollbar. This technique offers a scrollbar that is guaranteed to work, but may not look or behave like the system's scrollbars.
Parameter |
|
---|---|
workspace |
Workspace to bind the scrollbar to. Value must not be null. |
horizontal |
boolean True if horizontal, false if vertical. |
opt_pair |
Optional boolean True if scrollbar is part of a horiz/vert pair. |
opt_class |
Optional string A class to be applied to this scrollbar. |
Properties
scrollbarThickness
Width of vertical scrollbar or height of horizontal scrollbar in CSS pixels. Scrollbars should be larger on touch devices.
position
The upper left corner of the scrollbar's SVG group in CSS pixels relative to the scrollbar's origin. This is usually relative to the injection div origin.
ratio
nullable number
Methods
dispose
dispose()
Dispose of this scrollbar. Unlink from all DOM elements to prevent memory leaks.
isVisible
isVisible() returns boolean
Is the scrollbar visible. Non-paired scrollbars disappear when they aren't needed.
- Returns
-
boolean
True if visible.
resize
resize(opt_metrics)
Recalculate the scrollbar's location and its length.
Parameter |
|
---|---|
opt_metrics |
Optional A data structure of from the describing all the required dimensions. If not provided, it will be fetched from the host object. |
resizeContentHorizontal
resizeContentHorizontal(hostMetrics)
Recalculate a horizontal scrollbar's location within its path and length. This should be called when the contents of the workspace have changed.
Parameter |
|
---|---|
hostMetrics |
A data structure describing all the required dimensions, possibly fetched from the host object. Value must not be null. |
resizeContentVertical
resizeContentVertical(hostMetrics)
Recalculate a vertical scrollbar's location within its path and length. This should be called when the contents of the workspace have changed.
Parameter |
|
---|---|
hostMetrics |
A data structure describing all the required dimensions, possibly fetched from the host object. Value must not be null. |
resizeViewHorizontal
resizeViewHorizontal(hostMetrics)
Recalculate a horizontal scrollbar's location on the screen and path length. This should be called when the layout or size of the window has changed.
Parameter |
|
---|---|
hostMetrics |
A data structure describing all the required dimensions, possibly fetched from the host object. Value must not be null. |
resizeViewVertical
resizeViewVertical(hostMetrics)
Recalculate a vertical scrollbar's location on the screen and path length. This should be called when the layout or size of the window has changed.
Parameter |
|
---|---|
hostMetrics |
A data structure describing all the required dimensions, possibly fetched from the host object. Value must not be null. |
set
set(value)
Set the scrollbar handle's position.
Parameter |
|
---|---|
value |
number The distance from the top/left end of the bar, in CSS pixels. It may be larger than the maximum allowable position of the scrollbar handle. |
setContainerVisible
setContainerVisible(visible)
Set whether the scrollbar's container is visible and update display accordingly if visibility has changed.
Parameter |
|
---|---|
visible |
boolean Whether the container is visible |
setHandlePosition
setHandlePosition(newPosition)
Set the offset of the scrollbar's handle from the scrollbar's position, and change the SVG attribute accordingly.
Parameter |
|
---|---|
newPosition |
number The new scrollbar handle offset in CSS pixels. |
setOrigin
setOrigin(x, y)
Record the origin of the workspace that the scrollbar is in, in pixels relative to the injection div origin. This is for times when the scrollbar is used in an object whose origin isn't the same as the main workspace (e.g. in a flyout.)
Parameter |
|
---|---|
x |
number The x coordinate of the scrollbar's origin, in CSS pixels. |
y |
number The y coordinate of the scrollbar's origin, in CSS pixels. |
setPosition
setPosition(x, y)
Set the position of the scrollbar's SVG group in CSS pixels relative to the scrollbar's origin. This sets the scrollbar's location within the workspace.
Parameter |
|
---|---|
x |
number The new x coordinate. |
y |
number The new y coordinate. |
setVisible
setVisible(visible)
Set whether the scrollbar is visible. Only applies to non-paired scrollbars.
Parameter |
|
---|---|
visible |
boolean True if visible. |
updateDisplay_
updateDisplay_()
Update visibility of scrollbar based on whether it thinks it should be visible and whether its containing workspace is visible. We cannot rely on the containing workspace being hidden to hide us because it is not necessarily our parent in the DOM.