Create Vertical Live-Stream Bullet Comments with better-scroll

Add-ons
2026-07-25 23:10 5 次浏览 • 0 次下载 15.7KB
Create Vertical Live-Stream Bullet Comments with better-scroll

Last updated: 2021-05-01 01:12:18

Changelog:The better-scroll CDN link was broken, so all JavaScript files have been replaced with local files.


Last updated: 2020-05-05 22:39:33

better-scroll

better-scroll provides many flexible APIs. When implementing certain features based on better-scroll, these APIs come in handy. Understanding them helps you develop more complex functionality.


The best way to learn better-scroll is to explore its demo code, which is available in the example directory. Since Vue is currently one of the most suitable frontend MVVM frameworks for mobile development and works well with better-scroll, all demos have been rewritten using Vue.

1
2
3
4
5
6
7
8
<div >
<ul >
<li>...</li>
<li>...</li>
...
</ul>
<!-- Other DOM elements can be placed here without affecting scrolling -->
</div>

In the code above, better-scroll is applied to the outer wrapper container, while the content element is the part that scrolls. Note that better-scroll only handles scrolling of the first child element (content) inside the container (wrapper). All other elements are ignored.

The simplest initialization code is as follows:

1
2
3
import BScroll from 'better-scroll'
let wrapper = document.querySelector('.wrapper')
let scroll = new BScroll(wrapper)

better-scroll provides a class whose first constructor parameter is a native DOM object. Of course, if you pass a string, better-scroll will internally attempt to call querySelector to retrieve the DOM object. Therefore, the initialization code can also be written as follows:

1
2
import BScroll from 'better-scroll'
let scroll = new BScroll('.wrapper')
星河码客

发现和分享优质开源项目,传承互联网精神,为开发者服务。

关于本站

联系我们

微信/广告合作:ITcloub (备注星河码客)

免责声明:本站资源版权归原作者所有,仅供学习与交流。如有侵权,请通过「关于我们 - 侵权投诉」联系删除。

Powered by Nuxt · Deployed on Cloudflare