Built-in Component
NPlayer provides a number of built-in components that can facilitate secondary development and unified interaction.
You can access these components on the components properties or import them directly.
These components have the following similarities.
- The first parameter of the constructor is the container element of the component
elproperties, representing DOM elementdisposalmethod, calling this method will destroy components
Tooltip#
API#
constructor(container: HTMLElement, html?: string)#
第一个是容器元素,第二个是可选的 html 提示文字。
html#
获取或设置 innerHtml
show(): void#
显示 Tooltip。
hide(): void#
隐藏 Tooltip。
setLeft(): void#
与容器左对齐。
setRight(): void#
与容器右对齐。
setBottom()#
向下弹出。
resetPos()#
重置弹出位置。
Example#
Switch#
API#
constructor(container: HTMLElement, value?: boolean, change?: (v: boolean) => void)#
第二个参数表示当前是否是选中状态,第三个参数是 value 改变时的回调。
toggle(value?: boolean): void#
切换当前开关的值,如果传入 value 则表示强制设置成传入值的状态。
Example#
Popover#
API#
constructor(container: HTMLElement, onHide?: (ev?: MouseEvent) => void, style?: Partial<CSSStyleDeclaration>, left?: boolean)#
onHidewill be called when the popover is hiddenstylepopover styleleft是否和容器左对齐,默认是右对齐
panelEl: HTMLElement#
弹出框元素。
maskEl: HTMLElement#
遮罩元素。
applyPanelStyle(style: Partial<CSSStyleDeclaration>): void#
设置弹出框的样式。
show()#
显示弹出框。
hide()#
隐藏弹出框,你无需手动调用该函数,当用户点击弹出框外面时,会自动隐藏。
setBottom()#
弹出框将向下弹出。
resetPos()#
重置弹出框位置(向上弹出)。
Example#
Slider#
API#
constructor(container: HTMLElement, opts: SliderOption)#
opts.value当前的值,0 到 1 之间opts.stops滑块上的断点opts.change当用户修改滑块值是会调用opts.step滑动滑块时,是否自动吸附到最近的断点上
第三个参数是 player 播放器对象,如果传入该参数,当播放器尺寸变化是会自动更新滑块尺寸和位置,否则需要自己调用 slider.rect.update()。
rect: Rect#
可以通过它获取滑块的 width, height, x, y,调用 update 方法,将更新滑块尺寸。
update(value: number, x?: number, trigger = true): void#
手动更新滑块的值,第二个参数是滑块 x 的值,没有可以不传,内部会自动计算。第三个参数是是否触发 change 回调。
Example#
Checkbox#
API#
constructor(container: HTMLElement, opts: CheckboxOptions)#
opts.html复选框描述opts.checked当前是否选中change当值变动时的回调
update(v: boolean)#
Update currently checked or not.