现在,我需要在react中做翻页动画。我看到了用于页面翻转的turn.js库。我将其导入到 react 组件中。它没有调用该库中的 Jquery 函数(.turn)
导入声明
import React from 'react';
import $ from 'jquery'
import 'turn.js/index.js'
OnComponent 确实挂载方法:
componentDidMount(){
$("#flipbook").turn({
width: 400,
height: 300,
autoCenter: true
});
}
渲染时:
<div>
<div ref="flipbook">
<div className="hard"> Turn.js </div>
<div className="hard"></div>
<div> Page 1 </div>
<div> Page 2 </div>
<div> Page 3 </div>
<div> Page 4 </div>
<div className="hard"></div>
<div className="hard"></div>
</div>
</div>
浏览器控制台中出现错误:
Turn.js?36f0:16 Uncaught TypeError: jquery__WEBPACK_IMPORTED_MODULE_1___default(...)(...).turn is not a function
最佳答案
为什么不使用react-flip-page。它很好而且 react 灵敏。
使用 npm 安装它:
npm install --save react-flip-page
然后您可以使用FlipPage
作为组件。就像这样:
<FlipPage>
<article>
<h1>My awesome first article</h1>
<p>My awesome first content</p>
</article>
<article>
<h1>My wonderful second article</h1>
<p>My wonderful second content</p>
</article>
<article>
<h1>My excellent third article</h1>
<p>My excellent third content</p>
</article>
</FlipPage>
关于javascript - 我如何在 react 中包含第三方库(turn.js),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53302058/