imtaotao / danmu

Collision detection, highly customized danmu screen styles, you deserve it. (碰撞检测,高度自定义的弹幕样式,你值得拥有) 😘
https://imtaotao.github.io/danmu/
MIT License
320 stars 31 forks source link

添加弹幕,元素已经生成了,并且元素也播放动画在滚动,但是内容并没有出现在元素中 #16

Closed chenweilin0106 closed 2 months ago

chenweilin0106 commented 2 months ago
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/danmu/dist/danmu.umd.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            width: 100%;
            height: 100%;
        }
        .container {
            width: 100%;
            height: 500px;
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <div class="container"></div>
    <script>
        const manager = Danmu.create();
        manager.mount('.container');
        manager.startPlaying();
        manager.push('弹幕内容');
    </script>
</body>
</html>
imtaotao commented 2 months ago

得自己添加一个钩子把弹幕内容渲染到弹幕的节点里面,例如:

const manager = Danmu.create({
  plugin: {
    $createNode(danmaku) {
        console.log(danmaku.node);
        danmaku.node.textContent = danmaku.data;
     }
  }
});
manager.mount('.container');
manager.startPlaying();
manager.push('弹幕内容');

或者

const manager = Danmu.create();
manager.mount('.container');
manager.startPlaying();
manager.push('弹幕内容', { 
  plugin: {
      createNode(danmaku) {
        danmaku.node.textContent = danmaku.data;
      }
  }
});
chenweilin0106 commented 2 months ago

可以了,感谢作者;这一步我似乎没有在文档的快速开始中找到

imtaotao commented 2 months ago

可以了,感谢作者;这一步我似乎没有在文档的快速开始中找到

我更新了下文档。