javascriptjqueryionic2turnjs

Turn.js swipe left and right to turn


I am using turn.js in my Ionic2 project, when the user swipes from the left to right or right to the left page need to turn. How to trigger turn when I swipe?

file.ts

ngAfterViewInit() {
    var winWidth = window.innerWidth;
    var winHeight = window.innerHeight;

    console.log(winWidth,winHeight);

    jQuery("#flipbook").turn({
        width: winWidth,
        height: winHeight,
        display:'single',
        zoom: 0,
        turnCorners: "bl,br,tl,tr,l.r"
    });
}

Solution

  • Bind to jquery's swipeleft and swiperight events and call turn method on turnjs.

    jQuery( window ).on( "swipeleft", function( event ) { 
            $('#flipbook').turn('next');
                   } );
    
    
    jQuery( window ).on( "swiperight", function( event ) { 
            $('#flipbook').turn('previous');
                   } );