-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Reference
A new documentation is available on http://turnjs.com/docs
$('selector').turn([options]);
Creates an instance of turn.
Example: $('selector').turn({page:1});
options
- acceleration - Sets the hardware acceleration mode, default: true
- display (r3) - Defines the initial display, default:double
- duration - Sets the duration of the effect in microseconds, default: 600
- gradients - Sets the gradient mode, default: true
- height - Defines the height, default:
$('selector').height()
- inclination (r3) - Defines the inclination of the folded page when turning, default: 0
- page - Defines the initial page, default: 1
- pages - Sets the number of pages, default:
$('selector').children().length
- when (r3) - Defines the events (see the Event section for more), default: empty object
- width - Defines the width,
$('selector').width()
Gets the current display. The possible values are double
and single
.
$('selector').turn('display');
Gets the current page.
$('selector').turn('page');
Gets the number of pages.
$('selector').turn('pages');
Gets the current view. A view is basically an array of two values, in which the key [0] is the left page and [1] the right page.
In cases where there is only one page, the value will be zero.
$('selector').turn('view');
Adds a page using element
as content. If pageNumber
is not defined, the page will be added at the end
$('selector').turn('addPage', element[, pageNumber]);
Detects if there is an animation.
$('selector').turn('animating');
Sets the display. The possible values are double
and single
.
$('selector').turn('display', displayMode);
Disables and enables the effect.
$('selector').turn('disable', disableBool);
Detects if a page is already in the book or magazine.
$('selector').turn('hasPage', pageNumber);
Turns to the next view.
Example: $('selector').turn('next');
Turns to a specific page. The page number must be a Number.
$('selector').turn('page', pageNumber);
Sets the number of pages.
$('selector').turn('pages', numberOfPages);
Turns to the previous view.
Example: $('selector').turn('previous');
Gets a range of pages from pageNumber
needed to keep in memory.
$('selector').turn('range', pageNumber);
Removes a page
$('selector').turn('removePage', pageNumber);
Resets the size of all the wrappers used by turn.
$('selector').turn('resize');
Changes the size.
$('selector').turn('size', width, height);
Stops the current page flip effect.
$('selector').turn('stop');
Turn.js allows you to define events in two different ways:
- You can use the reserved key
when
within youroptions
for the initial configuration.
$('#selector').turn({when: {turn: function(e, page, view){ alert('page'+page); }}};
- Using the jQuery's method
bind
to add listeners.
$('#selector').bind('turn', turnEvent);
This event was removed in the 3rd release.
Fired when the page is set to 1.
Fired when the page is set to $('#selector').turn('pages')
Fired before the folded page appears.
Arguments
-
event - Event object
-
page - Page object
-
corner - Corner selected. The corners can be: tl (top left), tr (top right), br (bottom right), bl (bottom left).
Prevent default
It's possible to prevent the default action, which is to show the folded page. In order to prevent it, use event.preventDefault()
Fired before a page starts turning.
Arguments
-
event - Event object
-
page - The new page number
-
view - The new view.
Prevent default
The default action is to turn the page. In order to prevent it, use event.preventDefault()
Fired when a page has been turned.
Arguments
-
event - Event object
-
page - The new page number
-
view - The new view.
A subclass for specific pages.
Example:
Page 1 -> .p1 -> $('selector .p1')
Page 2 -> .p2 -> $('selector .p2')
A common subclass for every page.
- turn.js allows you to concatenate different methods, just like jQuery.
$('selector').turn('next').turn('next');
$('selector').turn('next').turn('previous');
$('selector').turn('next').turn('stop');
#syllabus div:nth-child(odd) { background-image: -webkit-linear-gradient(left, #fff 95%, #ddd 100%); background-image: -moz-linear-gradient(left, #fff 95%, #ddd 100%); background-image: -o-linear-gradient(left, #fff 95%, #ddd 100%); background-image: -ms-linear-gradient(left, #fff 95%, #ddd 100%); box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); }
#syllabus div:nth-child(even) { background-image: -webkit-linear-gradient(right, #fff 95%, #ddd 100%); background-image: -moz-linear-gradient(right, #fff 95%, #ddd 100%); background-image: -o-linear-gradient(right, #fff 95%, #ddd 100%); background-image: -ms-linear-gradient(right, #fff 95%, #ddd 100%); box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); } #syllabus .cover { background: #333; }