v2.0.3

HTMLElement and Link Extensions

Last updated


Layout and scroll helpers on HTMLElement.prototype, plus href/target setters on HTMLLinkElement.prototype.

HTMLElement


Source: src/prototype/HTMLElement.ts
Method / PropertyDescription
el._display(value)Chainable style.display = value; empty values are ignored
el.width(v) / height(v) / paddingTop(v) / paddingLeft(v) / paddingBottom(v) / paddingRight(v) / marginTop(v) / marginLeft(v) / marginBottom(v) / marginRight(v)Chainable numeric style setters; a bare number/numeric-string gets px appended automatically
el.padding(top, right?, bottom?, left?) / el.margin(...)CSS-shorthand-style chainable setter (1–4 args, same fallback rules as the padding/margin CSS property)
el.scrollToX(value, animation?) / el.scrollToY(value, animation?)Sets scrollLeft / scrollTop to scrollWidth - value / scrollHeight - value, or to clientWidth / clientHeight when value is smaller than the visible size; animation: true uses scrollTo with behavior: "smooth"; a non-number value is ignored
el.scrollToT(animation?) / el.scrollToB(animation?)Both call scrollToY(0), which sets scrollTop to clientHeight
el.scrollToL(animation?) / el.scrollToR(animation?)Both call scrollToX(scrollWidth - clientWidth), which sets scrollLeft to clientWidth

HTMLLinkElement


Source: src/prototype/HTMLLinkElement.ts
MethodDescription
link._go(href?)Chainable: sets href (if given) and target = "_self"; it does not navigate. Defined on <link> elements (HTMLLinkElement), not on <a>
link._open(href?)Chainable: sets href (if given) and target = "_blank"; it does not navigate

Example


Numeric setters append px; padding follows the CSS shorthand rules.
  1. <div id="box">box</div>
  2. <script>
  3. "box".$.width(120).height("48").padding(8, 16)._display("inline-block");
  4. console.log("box".$.style.cssText);
  5. </script>
Live preview · @pardnchiu/renderjs@2.0.3

The scroll helpers write the computed offsets shown in the table:
  1. <div id="pane" style="width:120px;height:60px;overflow:auto">
  2. <div style="width:600px;height:600px"></div>
  3. </div>
  4. <script>
  5. const pane = "pane".$;
  6. console.log("clientHeight:", pane.clientHeight, "scrollHeight:", pane.scrollHeight);
  7. pane.scrollToY(300);
  8. console.log("scrollToY(300):", pane.scrollTop);
  9. pane.scrollToT();
  10. console.log("scrollToT():", pane.scrollTop);
  11. pane.scrollToB();
  12. console.log("scrollToB():", pane.scrollTop);
  13. </script>
Live preview · @pardnchiu/renderjs@2.0.3
中文