虚拟元素
¥Virtual Elements
相对于自定义参考区域定位浮动元素,这对于上下文菜单、范围选择、跟随光标等非常有用。
¥Position a floating element relative to a custom reference area, useful for context menus, range selections, following the cursor, and more.
用法
¥Usage
最基本的虚拟元素是一个具有 getBoundingClientRect
方法的普通对象,它模模拟实元素的方法:
¥The most basic virtual element is a plain object that has a
getBoundingClientRect
method, which mimics a real
element’s one:
点引用(例如鼠标事件)就是这样的用例之一:
¥A point reference, such as a mouse event, is one such use case:
contextElement
如果你的 getBoundingClientRect
方法派生自真实元素,则此属性非常有用,以确保剪切和位置更新检测按预期工作。
¥This property is useful if your
getBoundingClientRect
method is derived from a real
element, to ensure clipping and position update detection works
as expected.
getClientRects
当使用范围选择和 inline
中间件时,此属性非常有用。
¥This property is useful when using range selections and the
inline
middleware.