我有一个包含多个组件的 React 单页应用程序。对于第 5 个组件(仅在向下滚动时可见),我有一个 counter 。现在我使用 react-countup 库来实现计数器功能。但是,计数器会在页面加载后立即启动。一旦我们向下滚动到组件,是否可以开始计数。动画仅在页面加载后发生一次(这很好),但我希望计数器不会在页面加载后不久开始,而是当用户第一次向下滚动到组件时。我的代码如下所示:
render() {
return (
<div className={style.componentName}>
<h2>Heading</h2>
<div className={style.col}>
<div>My counter</div>
<CountUp className={style.countup} decimals={1} start={0} end={25} suffix=" %" duration={3} />
</div>
</div>)}
Run Code Online (Sandbox Code Playgroud)
更新代码:
import CountUp, { startAnimation } from 'react-countup';
import VisibilitySensor from 'react-visibility-sensor';
class className extends Component {
state = {
scrollStatus: true
};
onVisibilityChange = isVisible => {
if (isVisible) {
if (this.state.scrollStatus) {
startAnimation(this.myCountUp);
this.setState({ scrollStatus: false });
}
}
}
render() {
return (
<div className={style.componentName}>
<h2>Heading</h2> …Run Code Online (Sandbox Code Playgroud) 我想在我的 angular 4 应用程序(使用 angular cli 构建)中使用 ngx-cookie 同意包。我没有 systemjs 文件。因此,除了那部分,我按照文档(https://tinesoft.github.io/ngx-cookieconsent/doc/index.html)中的每个步骤进行操作。我有 4 条错误消息
以下消息有两个错误
//Cannot read property 'initialise' of undefined at
//NgcCookieConsentService.init (cookieconsent.service.js:53)
//at new NgcCookieConsentService (cookieconsent.service.js:23)
//at _createClass (core.es5.js:9532)
//at createProviderInstance$1 (core.es5.js:9500)
//at resolveNgModuleDep (core.es5.js:948 5)
//at NgModuleRef.get (core.es5.js:10577)
//at resolveDep (core.es5.js:11080)
//at createClass (core.es5.js:10933)
//at createDirectiveInstance (core.es5.js:10764)
//at createViewNodes (core.es5.js:12212)
Run Code Online (Sandbox Code Playgroud)
请帮忙。