更新时间:2022-11-18 19:49:25
我是OnScreen的作者,它是一个小型库,可以在HTMLElement
进入视口或其容器的边界时调用回调函数./p>
I'm the author of OnScreen, a small library that can call a callback function when a HTMLElement
enters the viewport or the boundaries of its container.
// Uses ES6 syntax
import OnScreen from 'onscreen';
const os = new OnScreen();
os.on('enter', 'canvas', (element) => {
if (!element.chartInitialized) {
// Initialize the chart
// Update the `chartInitialized` property
// to avoid initializing it over and over
element.chartInitialized = true;
}
});
有关更多信息,请查看文档 .不要忘记查看 demos存储库中的几个简单示例.
For more information, take a look at the documentation. Don't forget to check the demos repo for a couple simple examples.