Create Smooth, Realistic Page Flip Animations with FlipBook.js
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.
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: An HTMLElement that, when clicked, will turn the page forward.previousButton: An HTMLElement that, when clicked, will turn the page backward.canClose: A boolean that determines if the book can be fully closed to show its front and back covers. Defaults to false.arrowKeys: A boolean that enables or disables page navigation using the left and right arrow keys. Defaults to true.initialActivePage: A number representing the zero-based index of the page you want the book to open to initially.onPageTurn: A callback function that executes every time a page is turned. It receives the flipbook element and an object containing active pages as arguments.initialCall: A boolean that, if true, triggers a subtle animation on the first page to draw the user’s attention. Defaults to false.width: A string defining the CSS width of the flipbook container (e.g., '800px' or '100%').height: A string defining 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. The direction argument can be the string 'forward', the string 'back', or a number representing the page index to jump to.getActivePages(): Returns an array of numbers, where each number is the index of a currently visible page.isFirstPage(): Returns a boolean indicating if the book is currently open to the first page.isLastPage(): Returns a boolean indicating if the book is currently open to the last page.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.
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.
The post Create Smooth, Realistic Page Flip Animations with FlipBook.js appeared first on CSS Script.
A new trailer for Dragon Ball Super: Beerus has arrived, teasing a look at not…
Bandai Namco has announced Dragon Ball Xenoverse 3 for PC via Steam, PlayStation 5, and…
ABILENE, Texas (KTAB/KRBC) – Abilene City Council Place 4 candidate Tammy Fogle is sharing her…
A new weekend has arrived, and today, you can save big on Apple AirTags, 4K…
Director Joe Russo has confirmed the upcoming Avengers: Endgame re-release will include new footage that…
Cooperative pirate survival game Windrose has reached 1 million copies sold less than a week…
This website uses cookies.