簡體   English   中英

我如何在響應中包含第三方庫(turn.js)

[英]How do i include the third parties Library (turn.js) in react

現在,我需要在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。 它的好,也反應迅速。

使用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>

這是參考鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM