A JavaScript plugin make a bullet screen using html5 canvas.
Including files:
<script src="js/hidpi-canvas.min.js"></script>
<script src="js/bulletScreen.min.js"></script>
HTML structure:
<canvas></canvas>
Create a object of BulletScreen
and initialize it.
// create
var bulletScreen = new BulletScreen();
// initialize
bulletScreen.init({
canvas: document.querySelector('canvas')
});
Then, you can add some comments.
var comments = [
{avatar: 'img/avatar.jpg', content: '啊哈哈哈'},
{avatar: 'img/avatar.jpg', content: '前方高能!!'},
{avatar: 'img/avatar.jpg', content: '233333333333'},
{avatar: 'img/avatar.jpg', content: '666666'}
];
// add comments
bulletScreen.addComments(comments);
Start to display the comments you added.
// start
bulletScreen.start();
Finally, you can continue to add more comments as you like. And all the "bullets" will fly on the screen.
If you want to configure the BulletScreen
object. just call the instance function configure
with a object.
// your customized config
var config = {
frameRate: 40,
bulletScreenInterval: 3000
}
// configure
bulletScreen.configure(config);
Your canvas's width and height.
Default: your browser's width and height.
FPS(Frames Per Second).
Default: 30.
Comments' font size.
Default: '16px'.
Comments' font family.
Default: 'Arial'.
Comments' font color.
Default: '#fff'.
Spacing between the adjacent rows.
Default: 10.
The radius of round avatars.
Default: 20.
The border width of round avatars.
Default: 6.
Height of comments content box.
Default: 28.
Border radius of comments content box.
Default: 6.
Background color of comments content box and color of avatars' border.
Default: '#fdb720'.
Interval of Comments show.
Default: 3000.
To initialize a BulletScreen
instance with a config object. About config option detail you can see above description.
Parameters:
- options: Object
To configure a BulletScreen
instance with a config object.
Parameters:
- options: Object
To add comments to the "bullet screen".
Parameters:
- comments: Array
Starting to display "bullet screen".
To pause displaying "bullet screen".
To resume starting to display the "bullet screen" which is paused.
To reset the config of a BulletScreen
instance and clearing the screen.