Limits
What the library does not handle, and what to do instead.
These are the known limits of version 2.0. Each row says what causes it and what to do instead. Behavior that was wrong before 2.0 and is fixed is not listed here.
| Limit | Cause | What to do instead |
|---|---|---|
| Touch input does not work as target |
A touch event has no position, so the result is NaN. A touch point is not an event, and
passing it throws a TypeError.
|
Use pointer events: listen to pointerdown and pointermove and pass the pointer
event as target. Pointer events work.
|
| Only mouse and pointer events work as target | The position is read from clientX and clientY of the event. |
Pass a mouse or pointer event, or an element or selector. |
A boundary of an iframe's window or document measures the page's own viewport
|
The library reads the viewport of the frame it runs in. | Pass an element inside the frame, for example its container, as boundary. |
| Wrong input types throw |
A number or other unexpected value as item, target, or an
at option throws a TypeError while the instance is created. The message is not
part of the API.
|
Pass an element, a selector string, or the documented keywords. |
A missing item gives null, not an error |
A selector that matches nothing leaves the item empty, and calculate() returns
null.
|
Check the result for null before you read moveBy. |
Calling resize() after a failed setup throws |
The instance has no item, so there are no sizes to read. | Create the instance with a valid item first. |
Without a doctype (quirks mode), the window boundary is the whole document |
The browser uses quirks layout, so the document box differs from the viewport. | Add <!doctype html>, or pass an element as boundary. |
Measuring a hidden item writes inline styles and loses an inline !important |
The library writes inline styles while it measures a hidden item, and an inline
!important is lost.
|
Show the item before you create the instance or call resize(). |
| Transforms: size and position come from different boxes | Sizes come from the layout box and positions from the transformed box. | Avoid transform on the item, the target, and the boundary when you position with them. |
| Sizes are whole pixels | Sizes come from offsetWidth and offsetHeight, which are integers. |
Expect sizes rounded to whole pixels. |
An offset without mirror means mirror: false |
The default offsets have mirror: true, but an offset object you pass does not inherit it.
|
Set mirror: true explicitly when the offset should follow a flip. |
A partial offset gives NaN |
An offset with only y or only x has no value for the other axis. |
Give both y and x, for example { y: 8, x: 0 }. |
stick is matched as text |
The library checks the string with indexOf, not against a list of names. |
Use only the edge names top, right, bottom, and
left, separated by spaces.
|
The IIFE build needs window |
The IIFE build uses window and has no type declarations. |
Import the ES module on the server, and load the IIFE only in the browser. |
| The IIFE build has no source map | The build does not ship a source map for the IIFE file. | Debug with the ES module build, the file without .iife. |
Not included
The library does not offer these. Each one needs your own code:
- a scroll container as boundary (only the window, the document, or an element you pass)
- automatic updates: call
calculate()again on scroll and resize - a virtual element, for example a point that is not in the DOM
- logical placement for right-to-left text, such as
startandend