/*
* Turn.js responsive book
*/
/*globals window, document, $*/
$("#page2").on("click", function(e){e.preventDefault();$(".book").turn("page", 2);})
$("#page4").on("click", function(e){e.preventDefault();$(".book").turn("page", 4);})
$("#page6").on("click", function(e){e.preventDefault();$(".book").turn("page", 6);})
(function () {
'use strict';
var module = {
ratio: 1.38,
init: function (id) {
var me = this;
// if older browser then don't run javascript
if (document.addEventListener) {
this.el = document.getElementById(id);
this.resize();
this.plugins();
// on window resize, update the plugin size
window.addEventListener('resize', function (e) {
var size = me.resize();
$(me.el).turn('size', size.width, size.height);
});
}
},
resize: function () {
// reset the width and height to the css defaults
this.el.style.width = '';
this.el.style.height = '';
var width = this.el.clientWidth,
height = Math.round(width / this.ratio),
padded = Math.round(document.body.clientHeight * 0.9);
// if the height is too big for the window, constrain it
if (height > padded) {
height = padded;
width = Math.round(height * this.ratio);
}
// set the width and height matching the aspect ratio
this.el.style.width = width + 'px';
this.el.style.height = height + 'px';
return {
width: width,
height: height
};
},
plugins: function () {
// run the plugin
$(this.el).turn({
gradients: true,
acceleration: true
});
// hide the body...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.