import {PageFlip} from 'page-flip';
const pageFlip = new PageFlip(document.getElementById('book'),
{
width: 400,
height: 600,
size: "fixed" // or "stretch"
//...
}
);
pageFlip.loadFromHTML(document.querySelectorAll('.page'));
npm install page-flip
PageFlip
from page-flip
package,
or just use <script/>
tag:
<script src="{path/to/scripts}/page-flip.browser.js"></script>
import {PageFlip} from 'page-flip';
const pageFlip = new PageFlip(htmlParentElement, settings);
// or if you're using a script tag and page-flip.browser.js:
const pageFlip = new St.PageFlip(htmlParentElement, settings);
htmlParentElement: HTMLElement
- root element where the book will be createdsettings
- a configuration object.
loadFromImages
:
pageFlip.loadFromImages(['path/to/image1.jpg', 'path/to/image2.jpg' ... ]);
loadFromHtml
pageFlip.loadFromHtml(items);
<div id="book">
<div class="my-page" data-density="hard">
Page Cover
</div>
<div class="my-page">
Page one
</div>
<div class="my-page">
Page two
</div>
<div class="my-page">
Page three
</div>
<div class="my-page">
Page four
</div>
<div class="my-page" data-density="hard">
Last page
</div>
</div>
const pageFlip = new PageFlip(document.getElementById('book'),
{
width: 400, // required parameter - base page width
height: 600, // required parameter - base page height
showCover: true
}
);
pageFlip.loadFromHTML(document.querySelectorAll('.my-page'));
Use the following data-density="hard"
attribute to specify page type (soft | hard
)
and define flipping animation.
width: number
- required. Base page widthheight: number
- required. Base page heightsize:("fixed", "stretch")
- default: "fixed"
.
Whether the book will be stretched under the parent element or notminWidth, maxWidth, minHeight, maxHeight: number
.
You must set threshold values with size: "stretch"
drawShadow: bool
- default: true
. Draw shadows or not when page flippingflippingTime: number
(milliseconds) - default: 1000
.
Flipping animation timeusePortrait: bool
- default: true
.
Enable switching to portrait modestartZIndex: number
- default: 0
.
Initial value to z-index
autoSize: bool
- default: true
.
If this value is true, the parent element will be equal to the size of the book
maxShadowOpacity: number[0..1]
- default: 1
.
Shadow intensity (1: max intensity, 0: hidden shadows)
showCover: boolean
- default: false
.
If this value is true, the first and the last pages will be marked as hard and will be shown in single page mode NEW on 0.3.0
mobileScrollSupport: boolean
- default: true
.
Disable content scrolling when touching a book on mobile devices NEW on 0.3.0
on
:
pageFlip.on('flip', (e) => {
console.log("Current page: " + e.data);
// callback code
}
);
flip: number
- triggered by page turningchangeOrientation: ("portrait", "landscape")
- triggered when page orientation changeschangeState: ("user_fold", "fold_corner", "flipping", "read")
-
triggered when the state of the book changesdata: number | string
and object: PageFlip
Name | Parameters | Return value | Description |
---|---|---|---|
getPageCount |
|
number |
Get number of all pages |
getCurrentPageIndex |
|
number |
Get the current page number (starts at 0) |
turnToPage |
pageNum: number |
void |
Turn to the specified page number (without animation) |
turnToNextPage |
|
void |
Turn to the next page (without animation) |
turnToPrevPage |
|
void |
Turn to the previous page (without animation) |
flip |
pageNum: number, corner: 'top' | 'bottom' |
void |
Turn to the specified page (with animation) NEW on 0.3.0 |
flipNext |
corner: 'top' | 'bottom' |
void |
Turn to the next page (with animation) |
flipPrev |
corner: 'top' | 'bottom' |
void |
Turn to the previous page (with animation) |
loadFromImages |
images: ['path-to-image'...] |
void |
Load page from images |
loadFromHtml |
items: NodeListOf | HTMLElement[] |
void |
Load page from html elements |
updateFromHtml |
items: NodeListOf | HTMLElement[] |
void |
Update page from html elements new on 0.4.0 |
updateFromImages |
images: ['path-to-image1.jpg', ...] |
void |
Update page from images new on 0.4.0 |
destroy |
|
void |
Destructor. Removes Parent HTML Element and all event handlers new on 0.4.0 |