turn.js icon indicating copy to clipboard operation
turn.js copied to clipboard

Prevent pageturn effect from blocking hovers/clicks

Open tvanassche opened this issue 14 years ago • 13 comments

I've recently started working on a flipbook for a client, and after some research settled on turn.js because it simply is the best pageflip javascript library you can find on the web at the moment (in my opinion).

While working on the project, I noticed that the pageturn effect blocks any hover-effects or clicks for buttons or links. This problem can be easily reproduced by simply putting a link or button right below a page in the flipbook. If you then hover over the corner of a page, the pageturn effect kicks in (by "folding" the corner of the page). When this happens, the "invisible" div (that is rotated 90 degrees) used for the effect covers up the link or button below the page, making it impossible to click on it in any browser other than Internet Explorer.

The fix for this is very simple: you just need to add "pointer-events: none" to the style of that "invisible" div. This will effectively allow clicks and hover-events to pass through the div that is responsible for the pageturn effect. This works in all modern browsers (Firefox 3.6+, Safari 4+ and Chrome) except for Opera.

original turn.js v0.11 code (around line 98)

divAtt = function(top, left, zindex, overf) { return {'css': { position: 'absolute', top: top, left: left, overflow: overf || 'hidden', 'z-index': zindex || 'auto' } }; },

fixed code

divAtt = function(top, left, zindex, overf) { return {'css': { position: 'absolute', top: top, left: left, overflow: overf || 'hidden', 'z-index': zindex || 'auto', 'pointer-events': 'none' //fix to let click/hover events go through the layer } }; },

tvanassche avatar Mar 27 '12 16:03 tvanassche

Thank you for the contribution! I will check that out.

blasten avatar Mar 28 '12 04:03 blasten

In the example provided with turn.js you can add a #container { width:800px; height:600px; overflow:hidden; } with the size of your book/magazine. This will prevent the behaviour you've described, also it will help keed the document size fixed. Might also work to set overflow:hidden to the #magazine div, haven't tried it though...

cipnt avatar Mar 28 '12 08:03 cipnt

@cipnt Yes, but then the pages just clip off when you drag their corners outside of the container, which looks weird if you as me.

Also tried to simply position the buttons above the pages, and while this also works, the buttons then "float" above the pages while dragging a page by it's corner. Which again looks weird.

The fix I proposed doesn't cause any undesired layout issues and doesn't break anything (tested in several versions of different browsers).

tvanassche avatar Mar 28 '12 08:03 tvanassche

You are right, I didn't even pay much attention to that, didn't noticed the corners being clipped. But I think my fix is good for mobile browsers, when you want the book/magazine to fill the entire screen (html width & height are the same as the book/magazine). Maybe if you use both solutions and add the bottom buttons/links inside the #container, making sure the width remains fixed.

cipnt avatar Mar 28 '12 09:03 cipnt

That's what I already did. I'm using a big container (with "overflow: hidden" on it) with everything inside it. Without the "overflow: hidden", the turn effect causes scrollbars to appear when the book takes up the whole screen, because the divs used for the turn effect are "breaking out" of the screen.

Right now i'm looking into resizing the books on the fly, and also looking into what the best size would be for different mobile devices.

tvanassche avatar Mar 28 '12 09:03 tvanassche

Any ideas how to fix this in version 4? I have tried your suggestion but now I cannot click anywhere inside the book.

michalhudecek avatar Aug 10 '12 08:08 michalhudecek

@michalhudecek It's solved in version 4. What problem do you exactly have?

blasten avatar Aug 16 '12 04:08 blasten

You are right. I meant peel animation, not page turn. I have started a different issue: https://github.com/blasten/turn.js/issues/142

michalhudecek avatar Aug 16 '12 06:08 michalhudecek

But what I fixed is the hard page turning blocking the clicks.

line #2073

data.bshadow = $('<div/>', divAtt(0, 0,  0,'hidden','none'));

line #2842

// Attributes for a layer

function divAtt(top, left, zIndex, overf, pointev) {

     return {'css': {
          position: 'absolute',
          top: top,
          left: left,
          'overflow': overf || 'hidden',
          zIndex: zIndex || 'auto',
          'pointer-events': pointev || 'auto',          
     }
};

}

Can you please implement it to the next version of turn.js version 4 so I don't have to customize it again?

Thanks

michalhudecek avatar Aug 16 '12 06:08 michalhudecek

@michalhudecek Nice, let me check that. Thanks!

blasten avatar Aug 17 '12 04:08 blasten

I have come up with better and more simple solution that doesn't cause this side-effect bug: https://github.com/blasten/turn.js/issues/142.

Update just line #2073 in the original turn to this one:

data.bshadow = $('<div/>', divAtt(0, 0,  0)).css("pointer-events","none");

Can you please implement it into the next version? Thanks.

michalhudecek avatar Sep 03 '12 16:09 michalhudecek

@michalhudecek Ok, let me check that out.

blasten avatar Sep 03 '12 17:09 blasten

It was disable corner in chrome. please!

adobetienduc avatar Jan 07 '14 23:01 adobetienduc