Prevent pageturn effect from blocking hovers/clicks
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 } }; },
Thank you for the contribution! I will check that out.
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 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).
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.
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.
Any ideas how to fix this in version 4? I have tried your suggestion but now I cannot click anywhere inside the book.
@michalhudecek It's solved in version 4. What problem do you exactly have?
You are right. I meant peel animation, not page turn. I have started a different issue: https://github.com/blasten/turn.js/issues/142
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 Nice, let me check that. Thanks!
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 Ok, let me check that out.
It was disable corner in chrome. please!