jabbany / CommentCoreLibrary

Javascript Live Comment (Danmaku) Engine Implementation. JS弹幕模块核心,提供从基本骨架到高级弹幕的支持。
http://jabbany.github.io/CommentCoreLibrary/demo
MIT License
1.9k stars 304 forks source link

弹幕前可以加头像图片嘛??? #130

Closed LJG-V closed 2 years ago

LJG-V commented 2 years ago

类似一条弹幕: 【img】文本

dbFlower commented 2 years ago

已收到

VirusYu commented 2 years ago

我是通过源码中增加属性avatar实现的,在两个方法中添加,然后添加弹幕数据时有选择的增加属性就好了

function CoreComment(parent, init) {
    ...
    if (init.hasOwnProperty('avatar')) {
        this.avatar = init['avatar']
    }
    ...
}
CoreComment.prototype.init = function(recycle) {
    ...
    if(this.avatar) {
        const avatar = document.createElement('img');
        avatar.src = this.avatar;
        this.dom.appendChild(avatar)
    }
    ...
}
jabbany commented 2 years ago

基本上就是靠上面这么个方法去做。当然如果在用 TypeScript 可以直接改 src/core/Comment.ts 里面的对应方法(或者创造一个子类来加这个功能),然后重新编译即可。