Scrollbars

From PowerUI
Revision as of 22:59, 24 September 2017 by 81.140.47.28 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PowerUI scrollbars, like all other UI components, are entirely defined in HTML and are easy to style. They consist of these three components:

<!-- The element itself (you can actually use this directly too; see more below) -->
<scrollbar>

<!-- The draggable thumb -->
<scrollthumb>

<!-- The up/down/left/right buttons -->
<scrollbutton>

An extra component which may also appear in the bottom right corner is the resizer:

<!-- The resizable corner -->
<resizer>

Using a custom scrollbar - the scrollbar element

Normally you would use overflow:scroll or overflow:auto to get them to appear, but if you'd like a custom scrollbar to do whatever you want with, then here's some examples:

<!-- A vertical scrollbar -->
<scrollbar target='elementID' orient='vertical'/>

<!-- A horizontal scrollbar -->
<scrollbar target='elementID' orient='horizontal'/>
Attribute name Optional What it's for Default value Possible values
target yes The element ID the scrollbar will scroll none An element ID.
orient yes Is this a vertical or horizontal scrollbar horizontal horizontal, vertical

When the thumb is dragged around, the scrollbar will fire an onchange event. You can hook up those events in the same way you would any other element. To obtain progress information, you'll want to get hold of the thumb element (available via scrollbarElement.Thumb).

Overflow:auto or Overflow:scroll

When an element automatically generates scrollbars, they become virtual elements in the shadow DOM. To access those, see more on virtual elements.

Internal DOM Structure

Don't type this out to use a scrollbar - this is provided for CSS selection purposes:

<!-- A complete vertical scrollbar -->
<scrollbar orient='vertical'>
  <scrollbutton part='start' orient='up'/>
  <scrollthumb orient='vertical'/>
  <scrollbutton part='end' orient='down'/>
</scrollbar>

<!-- A full horizontal scrollbar -->
<scrollbar orient='horizontal'>
  <scrollbutton part='start' orient='left'/>
  <scrollthumb orient='horizontal'/>
  <scrollbutton part='end' orient='right'/>
</scrollbar>

The scrollbars act like direct child nodes of the element which is overflowing.

Thumb and button attributes

Both the buttons and the thumb automatically set some additional attributes which can be used with the attribute CSS selector.

Attribute name Optional What it's for Default value Possible values
part no Start or end of the scrollbar none start, end
orient no Orientation of the button none Buttons: up, down, left, right; Thumb: horizontal, vertical

Styling examples

/* Every scrollbar will have a blue background */
scrollbar{
 background:blue;
}

/* Just the scrollbars on the div with id='myOverflowingDiv' will have green backgrounds */
#myOverflowingDiv scrollbar{
 background:green;
}

/* All horizontal scrollbars */
scrollbar[orient="horizontal"]{
 border:1px solid black;
}

/* All scroll buttons */
scrollbutton{
 background:orange;
}

/* All down pointing scroll buttons */
scrollbutton[orient="down"]{
 background:red;
}

/* All buttons at the "end" of the bar (down and right) */
scrollbutton[part="end"]{
 background:yellow;
}