
FlipBook.js is a lightweight JavaScript plugin that creates smooth, interactive flip books with realistic page-turning animations.
Perfect for children’s storybooks, digital magazines, product catalogs, or portfolios where you want a more engaging experience than a simple slider or a long scroll.
Features:
- Responsive Design: Adapts to different screen sizes with configurable width and height parameters.
- Keyboard Navigation: Supports left and right arrow key controls for improved accessibility.
- Custom Navigation Buttons: Accepts external button elements for next and previous page functionality.
- Page Jump Capability: Allows direct navigation to specific pages by index number.
- Attention Animation: Includes an optional callout effect that draws user attention to available interactions.
- Cover Mode: Optional front and back cover functionality that mimics physical book behavior.
- Cross-Browser Support: Includes fallbacks for browsers without CSS3 transform support.
See it in action:
How to use it:
1. Download the plugin and load the following files in your HTML document.
<link rel="stylesheet" href="flipbook.min.css"> <script src="flipbook.umd.min.js"></script>
2. For projects using a build step, you can install it via npm:
# NPM $ npm install flipbook-js
And then import it into your project:
// ES Module import FlipBook from 'flipbook-js'; import 'flipbook-js/style.css';
3. Create a main container and then add a div with the class c-flipbook__page for each page of your book.
<div class="c-flipbook" id="my-book">
<div class="c-flipbook__page">
<!-- Page 1 Content -->
</div>
<div class="c-flipbook__page">
<!-- Page 2 Content -->
</div>
<div class="c-flipbook__page">
<!-- Page 3 Content -->
</div>
...
</div>3. Initialize the plugin by creating a new instance and passing it the ID of your book’s container element.
const myBook = new FlipBook('my-book');4. Customize the flipbook through the following configuration parameters:
nextButton: AnHTMLElementthat, when clicked, will turn the page forward.previousButton: AnHTMLElementthat, when clicked, will turn the page backward.canClose: Abooleanthat determines if the book can be fully closed to show its front and back covers. Defaults tofalse.arrowKeys: Abooleanthat enables or disables page navigation using the left and right arrow keys. Defaults totrue.initialActivePage: Anumberrepresenting the zero-based index of the page you want the book to open to initially.onPageTurn: A callbackfunctionthat executes every time a page is turned. It receives the flipbook element and an object containing active pages as arguments.initialCall: Abooleanthat, iftrue, triggers a subtle animation on the first page to draw the user’s attention. Defaults tofalse.width: Astringdefining the CSS width of the flipbook container (e.g.,'800px'or'100%').height: Astringdefining the CSS height of the flipbook container (e.g.,'600px').
const myBook = new FlipBook('my-book',{
nextButton: null,
previousButton: null,
canClose: false,
arrowKeys: true,
initialActivePage: 0,
onPageTurn: () => {},
initialCall: false,
width: '100%',
height: '283px',
});5. API methods.
turnPage(direction): Turns the page. Thedirectionargument can be the string'forward', the string'back', or anumberrepresenting the page index to jump to.getActivePages(): Returns an array ofnumbers, where each number is the index of a currently visible page.isFirstPage(): Returns abooleanindicating if the book is currently open to the first page.isLastPage(): Returns abooleanindicating if the book is currently open to the last page.
How it works:
FlipBook.js works by applying CSS3 transforms to create the illusion of 3D page rotation. The library uses perspective and rotateY transforms to position pages in three-dimensional space, with careful z-index management to ensure proper layering during transitions.
The core animation system relies on transform-origin properties to create realistic pivot points. Left-side pages rotate around their right edge, while right-side pages rotate around their left edge. This approach mimics the natural mechanics of physical book pages.
For browsers lacking CSS3 transform support, the library includes a fallback system that simply shows and hides pages using display properties.
The event system uses transition end listeners to clean up animation classes and update page states. This prevents visual artifacts during rapid navigation attempts.
FAQs:
Q: Can FlipBook.js handle dynamic content loading?
A: Yes, you can add content to page elements after initialization. The library automatically detects page structure changes when methods like turnPage() are called. For optimal performance, populate pages before initialization when possible.
Q: How do I add custom styling to pages?
A: Apply CSS styles directly to elements with the ‘c-flipbook__page’ class. The library preserves your custom styles while adding its own transform and positioning properties. Avoid modifying transform-related CSS properties as these are managed by the library.
Q: Is it possible to implement custom page indicators?
A: Use the getActivePages() method and onPageTurn callback to track page changes and update custom indicators. The callback provides access to the current page state after each navigation action.







