mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 16:11:20 -08:00
feat(danmuku): add unique identifier for danmuku items
- Introduced a new dataset attribute `data-id` to DOM elements for unique identification of danmuku items. - Updated validation to include an optional `id` field for danmuku objects. - Changed the property `$id` to `$index` for better clarity on its purpose as an index rather than a unique identifier. - Ensured the `data-id` attribute is set for visibility control during hover interactions.
This commit is contained in:
1 parent
35ad9883af
commit
f3c0a9a77d
3 files changed
+10
-3
No files matched your search
@@ -397,6 +397,7 @@ class Danmuku {
|
||||
const $ref = this.$refs.pop() || document.createElement('div');
|
||||
$ref.style.cssText = Danmuku.cssText;
|
||||
$ref.dataset.mode = '';
|
||||
$ref.dataset.id = '';
|
||||
$ref.className = '';
|
||||
return $ref;
|
||||
}
|
||||
@@ -492,6 +493,7 @@ class Danmuku {
|
||||
async emit(danmu) {
|
||||
const { clamp } = this.utils;
|
||||
this.validator(danmu, {
|
||||
id: '?string',
|
||||
text: 'string',
|
||||
mode: '?number',
|
||||
color: '?string',
|
||||
@@ -522,7 +524,7 @@ class Danmuku {
|
||||
const item = {
|
||||
...danmu,
|
||||
$state: 'wait',
|
||||
$id: this.index++,
|
||||
$index: this.index++,
|
||||
$ref: null,
|
||||
$restTime: 0,
|
||||
$lastStartTime: 0
|
||||
@@ -675,6 +677,8 @@ class Danmuku {
|
||||
danmu.$ref.style.visibility = 'visible';
|
||||
danmu.$ref.dataset.mode = danmu.mode // CSS控制模式的显示和隐藏
|
||||
;
|
||||
danmu.$ref.dataset.id = danmu.id || '' // 用于悬停的唯一标识
|
||||
;
|
||||
switch(danmu.mode){
|
||||
// 滚动的弹幕
|
||||
case 0:
|
||||
|
||||
Reference in new issue
Block a user