Is there a way to adjust the height of a turnjs page?

I am currently utilizing the Turn.js flip library and I need to adjust the height of the turnjs page. The current setup calculates the height of the page based on the client's height, but now I want to change it to a specific value like 700px. How can I go about achieving this?

<script type='text/javascript'>
    (function () {
        'use strict';
        var module = {
            ratio: 1.38,
            init: function (id) {
                var me = this;
                if (document.addEventListener) {
                    this.el = document.getElementById(id);
                    this.resize();
                    this.plugins();
                    window.addEventListener('resize', function (e) {
                        var size = me.resize();
                        $(me.el).turn('size', size.width, size.height);
                    });
                }
            },
            resize: function () {
                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 (height > padded) {
                    height = padded;
                    width = Math.round(height * this.ratio);
                }
                this.el.style.width = width + 'px';
                this.el.style.height = height + 'px';
                return {
                    width: width,
                    height: height
                };
            },
            plugins: function () {
                $(this.el).turn({
                    gradients: true,
                    acceleration: true
                });
                document.body.className = 'hide-overflow';
            }
        };
        module.init('book');
    }());
</script>

html:

<div class="t">
    <div class="tc rel">
        <div class="book" id="book">    
            <div class="page page1">
                <img src="image600x650.png">
            </div>
        </div>
    </div>
</div>

Answer №1

Find all the details you need on the official site. The process involves executing a similar command as shown below:

$("flipbook").height(700);

Answer №2

Check out the following code for a magazine with a height of 500px and width of 992px. function loadApp() {

    flipbook.turn({

        // Magazine width

        width: 922,

        // Magazine height
        // Adjust the height below as needed

        height: 500,

    }

});

Also, make changes to the magazine.css file or add styles like the ones below to set your desired height:

.magazine-viewport .container{
    width: 922px;
    height: 500px;
}

.magazine-viewport .magazine{
    width: 922px;
    height: 500px;
}

.magazine-viewport .page{
    width: 922px;
    height: 500px;
}
.magazine-viewport .next-button,
.magazine-viewport .previous-button{
    width: 22px;
    height: 500px;
}

Answer №3

Within the main.js file

function loadApp() {

$('#canvas').fadeIn(1000);

var flipbook = $('.magazine');

// Verify if the CSS has been loaded

if (flipbook.width()==0 || flipbook.height()==0) {
    setTimeout(loadApp, 10);
    return;
}

// Initialize the flipbook

flipbook.turn({

        // Magazine width

        // width: 922,
        width: 1245,

        // Magazine height

        // height: 600,
        height: 810,

        // Duration in milliseconds

        duration: 1000,

        // Hardware acceleration

        acceleration: !isChrome(),

        // Enable gradients

        gradients: true,

        // Automatically center the flipbook

        autoCenter: true,

        // Elevation from the edge of the flipbook when turning a page

        elevation: 50,

        // Total number of pages

        pages: 12,

        // Event handlers

        when: {
            turning: function(event, page, view) {

                var book = $(this),
                currentPage = book.turn('page'),
                pages = book.turn('pages');

                // Update the current URI

                Hash.go('page/' + page).update();

                // Toggle navigation buttons

                disableControls(page);


                $('.thumbnails .page-'+currentPage).
                    parent().
                    removeClass('current');

                $('.thumbnails .page-'+page).
                    parent().
                    addClass('current');



            },

            turned: function(event, page, view) {

                disableControls(page);

                $(this).turn('center');

                if (page==1) { 
                    $(this).turn('peel', 'br');
                }

            },

            missing: function (event, pages) {

                // Add pages that are not currently part of the magazine

                for (var i = 0; i < pages.length; i++)
                    addPage(pages[i], $(this));

            }
        }

});

Answer №4

It's as easy as pie - just tweak the 'ratio' setting to customize the dimensions. For instance, a ratio of 1 means the width is equal to the height, while a ratio of 2 indicates double the height. A ratio of 1.5 suggests a proportion relative to the height. In the case of 600x650, the ratio works out to be 1.083.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Trouble with JavaScript event listener/button functionality

Seeking a simple fix here. While I have experience in Java, I am slowly but surely delving into Javascript. Currently, I am working on creating a fun website. The specific task at hand involves utilizing the parse api. My approach (as there seemed to be ...

Initiating and handling a POST request

In my node.js server, I have a simple setup like this: var express = require('express'); var app = express(); app.post('/savearticles', function (req, res) { res.send(req.body); }); Additionally, the javascript code is not very c ...

Can a nested array be divided into two separate arrays in Javascript?

I have received an array structured like this var cars = [['BMW'],[],['6000cc']]; This array includes two distinct values of the same item. The presence of an empty array indicates a change in data. The data on the left side of the e ...

Creating a JavaScript array with each element being a pair of objects

Hey there! I'm trying to create an array where each element is a pair of objects. Something like this: var Shelves = new arr[][] var books = new Books[] ; Shelves[book[i], book[j=i+1]], [book[i+1], book[j=i+1]] and so on......; I know how to use a f ...

Ways to reuse test cases across different test suites in Protractor

There are some shared test cases that can be utilized across different test suites. For example, suppose suite x and suite y both require the same set of test cases to function properly. To address this, a separate .js file containing the shared code has ...

VueJS - The application is unable to find the designated route

I've encountered an issue with the Signin page in my project. Despite having all other pages functioning properly, the Signin page doesn't seem to render anything when I navigate to it (http://localhost:8080/#/signin). import Vue from 'vu ...

Utilizing CSS flex-end to position images

I am facing an issue with aligning the last item in my container named section-a. The height of the container is set to 100vh and it contains 3 items. I have tried using the property align-self:flex-end, but there are no visible changes. Can anyone help me ...

The oversized image is refusing to scale down to fit within the confines of the CSS grid container

I am currently facing a challenge with creating a responsive image within a grid layout using CSS. The image is not resizing properly when the browser window changes size and is extending beyond its container borders. I have experimented with various techn ...

Unusual Quirks with jQuery's .post Method

I have noticed that my liking function is running the .post request 12 times, whereas my follow script with similar jQuery code does not have this issue. I have checked my fave.php and unfave.php files for errors, but they seem to be similar to my follow.p ...

Is there a way to utilize a single function on two separate div elements?

Looking for a way to optimize my code that contains the addRow() and deleteRow() functions. Currently, I have duplicated these functions for both radio buttons and checkboxes. Is there a more efficient way to achieve this? function addRow(tableID) { ...

CSS animation displays on top as it runs

My issue involves animating 2 blinking eyes that appear on top of my navigation bar when I scroll the page. Surprisingly, this doesn't happen without the animation. How can I ensure that the animation runs smoothly under the navigation bar? I have tri ...

"Can anyone explain why my plugin is displaying the error message 'Definition for rule was not found'

Introducing my custom plugin You can find the plugin here: @bluelovers/eslint-plugin For the base config, visit: https://github.com/bluelovers/ws-node-bluelovers/blob/master/packages/eslintrc/.eslintrc.json When it comes to the runtime user config: { ...

Utilizing JSON data from Google Maps Matrix with JavaScript

I am trying to fetch the real-time duration of a particular route on Google Maps through my JavaScript code. However, I seem to be stuck. Here's what I have written so far: $(document).ready(function Duration() { var d = new Date(); $.ajax({ ...

Angular 4's Mddialog experiencing intermittent display problem

While using MDDialog in my Angular app, I've encountered a couple of issues. Whenever a user clicks on the div, flickering occurs. Additionally, if the user then clicks on one of the buttons, the afterclose event is not triggered. Can anyone provide ...

Using Node.js to Insert Data into MySQL

I recently started experimenting with node.js and decided to use node-mysql for managing connections. Even though I am following the basic instructions from the github page, I am unable to establish a simple connection successfully. var mysql = require(& ...

PHP, AJAX and MySQL - dynamically refreshing a web page with multiple dropdown menus

I have a current setup that allows me to select a minimum price for display, and the page updates accordingly without any issues. However, I also want to set a maximum price for display from a different <select> (and in the future, other options such ...

Prompting for confirmation when the "Close Button" is clicked in Bootstrap V5 Alert Dismissing

Looking to enhance the user experience by incorporating Sweetalert2 for a confirmation message within the Bootstrap version 5 alert component. Curious how it operates? Upon clicking the "Close Button" (X), the intention is to trigger a confirmation messa ...

When using jQuery without $.ajax, the combination of $.POST and json functions will return "null" when retrieving data from PHP's json_encode

Although I am writing for the first time, I have been a part of this community before. I decided to post my query here because none of the similar questions seemed to offer a clear solution to my specific issue. I am currently working on a tic-tac-toe gam ...

Ways to modify the source of images that do not possess a class or ID using JavaScript

I'm struggling to change the source of the img element using JavaScript and Ajax. The img tag doesn't have any IDs or classes, making it difficult for me to select and update the src. Can anyone provide guidance on how I can accomplish this? Belo ...

Using jQuery AJAX to showcase HTML responses on a webpage

My current approach to utilizing jquery ajax is as follows: $.ajax({ url: url, type: "POST", data: data, success: function (response) { if ( foo ) { alert("foo happened"); / ...