diff --git a/packages/artplayer-plugin-playlist/src/index.js b/packages/artplayer-plugin-playlist/src/index.js index 6a303f3c6..48bf86b0f 100644 --- a/packages/artplayer-plugin-playlist/src/index.js +++ b/packages/artplayer-plugin-playlist/src/index.js @@ -2,7 +2,7 @@ import './index.scss'; function artplayerPluginPlaylist(art) { const { - utils: { append, errorHandle, sleep }, + utils: { append, errorHandle, sleep, inverseClass }, } = art.constructor; const { player, @@ -70,11 +70,9 @@ function artplayerPluginPlaylist(art) { art.on('afterAttachUrl', () => { const index = playlist.findIndex(item => item.url === $video.src); - const $children = Array.from($playlistInner.children); - const $item = $children[index]; + const $item = Array.from($playlistInner.children)[index]; if (index !== -1 && $item) { - $children.forEach(item => item.classList.remove('active')); - $item.classList.add('active'); + inverseClass($item, 'active'); } }); diff --git a/packages/artplayer/src/utils/index.js b/packages/artplayer/src/utils/index.js index 1a4da70f9..b18310b15 100644 --- a/packages/artplayer/src/utils/index.js +++ b/packages/artplayer/src/utils/index.js @@ -99,9 +99,9 @@ export function append(parent, child) { if (child instanceof Element) { parent.appendChild(child); } else { - parent.insertAdjacentHTML('beforeend', child); + parent.insertAdjacentHTML('beforeend', String(child)); } - return parent.lastElementChild; + return parent.lastElementChild || parent.lastChild; } export function remove(child) {