javascriptjqueryjquery-pluginsturnjs

How to get zoom working with turn.js


I am trying to make a flipbook using turn.js that has the same functionality as the example on the website http://www.turnjs.com/samples/magazine/

When looking at how to achieve this I came across these pages
http://www.turnjs.com/docs/Method:_zoom
http://turnjs.com/docs/How_to_add_zoom_to_turn.js

But after following these instructions on the pages my flipbook works nothing like the sample one.

I tried using the sample provided and breaking it down into sections to get mine working but I have not gotten any closer to solving this problem and the sample contains a bunch of other scripts and I am not sure if they are required for the zoom or are used for other things.

Not sure if I am missing something really simple or if my code is really off but my html looks something like this.

Right now all I get when clicking the zoom button is that the book scales up 150%

Was wondering if anyone could tell me what I am missing to get that zoom?

<div class="row">
   <div id="zoom-viewport">
      <div id="flipbook">   

          // wordpress loop

               <div class="page">
                    // page contents
               </div>

          // end loop

      </div>                        
   </div>
</div>

and jQuery

    //----------------------------
    // Initialize

    var _width = $('#flipbook-wrap').width(),
        _height = Math.round(70.909090909/100*_width),
        _winWidth = $window.width(),
        _winHeight = $window.height();

    $("#flipbook").turn({
        width: _width,
        height: _height,
        autoCenter: true
    });

    //----------------------------
    // Zoom in button

    $('.fullscreen').click(function(e){
        e.preventDefault();
        $("#flipbook").turn("zoom", 1.5);

    });

Solution

  • Your code isn't showing everything (e.g. where ".fullscreen" or the "zoom button" is in your HTML), so my answer may not be precise.

    Looking at the sample, you should find the code:

    $('.magazine-viewport').zoom('zoomIn', pos);
    

    This seems to differ from turn('zoom', ...), and appears to be undocumented. This is a function that will zoom in the element defined as a turn object. I believe, for you, this is your "#flipbook" element, instead of ".magazine-viewport".

    The parameters are "zoomIn" and pos, which may be a different functionality that what you're using currently. The "pos" appears to be a JS object that contains "x" and "y" properties, meant to define where you clicked on the magazine. These coordinates are relative to the magazine, not the whole screen, so keep that in mind.

    So, I think you need something like this (at least try it at a starting point):

    $('#flipbook').click(function(e) {
        var pos = {
            x: e.pageX - $(this).offset().left,
            y: e.pageY - $(this).offset().top
        };
        $('#flipbook').zoom('zoomIn', pos);
    });
    

    Hope this helps!