6.4 KiB
turn.js 3rd release, local maintenance fork
turn.js is a jQuery plugin that renders HTML pages as a book or magazine with a page-turn transition.
This repository contains a maintained local copy of the original turn.js 3rd release. The current work focuses on making the library easier to test and safer to use with modern jQuery versions while keeping the original API shape.
French version: README.fr.md
Current Status
This fork has been smoke-tested with jQuery 4.0.0 in the minimal demo and covered by automated unit and visual tests. The core plugin can initialize, navigate, resize, add/remove pages, and destroy itself in modern browser test runs.
Compatibility is not yet guaranteed for every modern browser or device. Safari/WebKit, iOS, Android touch behavior, accessibility, and production visual regressions still need dedicated validation.
What Changed
- Updated internal event registration from deprecated jQuery
.bind()/.unbind()patterns to.on()/.off(). - Modernized input events to prefer Pointer Events when available, with the existing touch and mouse paths kept as fallbacks.
- Added event namespaces:
.turnfor book-level and document-level turn.js events..turnFlipfor internal flip-page events.
- Added a public
destroymethod:- stops animations;
- detaches turn.js event handlers;
- removes turn and flip wrappers;
- restores original page elements as direct children;
- restores original
styleandclassattributes; - removes turn.js internal jQuery data while preserving unrelated user data.
- Replaced the internal
setIntervalanimation loop withrequestAnimationFrame. - Fixed
animatef(false)so cancelling an animation cancels the scheduled animation frame. - Modernized CSS output:
- gradients now use standard
linear-gradient(...deg, ...); - fold gradients keep normalized
0-100%stops and use softer shadow-only colors; - transforms now write standard
transformandtransform-originproperties, with a prefixed fallback when detected.
- gradients now use standard
- Moved static wrapper styles to
turn.cssand internal classes, while keeping dynamic size, position, z-index, transform, and gradient values inline. - Added a minimal browser demo using jQuery
4.0.0. - Added text and local images to the minimal demo.
- Fixed minimal demo layout so turn.js page measurements match the real rendered page size.
- Added unit tests with Vitest and JSDOM.
- Added Playwright visual tests and reference snapshots for the minimal demo.
- Added npm scripts and project configuration for automated tests.
- Regenerated
turn.min.jsfrom the updated source.
Demo
Open the minimal demo directly in a browser:
xdg-open demos/minimal/index.html
The demo loads:
- jQuery
4.0.0from the jQuery CDN; ../../turn.css;../../turn.js;- local image assets from
demos/minimal/assets.
It includes a six-page book, previous/next controls, keyboard navigation, text, and images.
Installation for Development
Install dependencies:
npm install
The development dependencies include:
jquery4.0.0;vitest;jsdom;@playwright/test.
Usage
Basic HTML:
<div id="magazine">
<div>Page 1</div>
<div>Page 2</div>
<div>Page 3</div>
<div>Page 4</div>
</div>
Basic CSS:
#magazine {
width: 800px;
height: 400px;
}
#magazine .turn-page {
background: #f4f4f4;
}
Basic JavaScript:
<link rel="stylesheet" href="turn.css">
<script src="https://code.jquery.com/jquery-4.0.0.min.js"></script>
<script src="turn.js"></script>
<script>
$('#magazine').turn({
width: 800,
height: 400,
gradients: true,
acceleration: true
});
</script>
turn.css contains the static styles for turn.js internal wrappers. turn.js also injects these base rules as a fallback for existing pages that only load the script, but loading the stylesheet explicitly is recommended.
Destroying an instance:
$('#magazine').turn('destroy');
After destroy, the original page elements are restored as direct children of #magazine, turn.js wrappers are removed, and the element can be initialized again.
API Notes
Supported public turn API:
init/$('#magazine').turn(options)pagenextpreviousaddPageremovePagepagessizedisplaydisabledestroy
Methods whose names start with _ are private implementation details. Other legacy helpers may still exist for internal compatibility, but they are not documented as supported API.
The new destroy method is intended for teardown in single-page applications, tests, page transitions, and any workflow where a book needs to be removed or initialized again without leaving DOM wrappers or document event handlers behind.
Tests
Run the full test suite:
npm test
Run only unit tests:
npm run test:unit
Run only Playwright visual tests:
npm run test:visual
Update Playwright snapshots after an intentional visual change:
npm run test:visual:update
The current suite covers:
- plugin registration;
- initialization state;
- initial page selection;
- dynamic
addPage/removePage; - event namespace registration;
destroycleanup and re-initialization;requestAnimationFramescheduling and cancellation inanimatef;- standard CSS transform property writing;
- bounded, shadow-only fold gradients during animation;
- minimal demo rendering;
- page turn rendering;
- compact viewport geometry;
- page measurements during animation.
Requirements
- Node.js for development and tests.
- jQuery
4.0.0for the current maintained demo and test setup. - A browser supported by Playwright for visual tests.
Older jQuery versions were part of the compatibility spike, but this repository now uses jQuery 4.0.0 as the modern target for its demo and automated tests.
Browser Support
The original README listed Chrome 12, Safari 5, Firefox 10, and IE 9 for the historical 3rd release.
This maintained copy targets modern browsers, but the current automated coverage is limited to the configured Playwright browsers and the local test environment. Treat Safari/WebKit, mobile touch devices, and accessibility behavior as open validation work.
License
Released under the original non-commercial BSD license. See license.txt.
Original Project
- Original site: turnjs.com
- Original documentation: GitHub wiki reference