CSS Flipping Page Effect

xialin picture xialin · Oct 14, 2013 · Viewed 16.4k times · Source

I'm building an web application with effect similar to FlipBoard.

At first, I was trying to use this open source. But I don't really like the way it's implemented (create duplicates for each page and overlap each other when rotate)... plus, when I add dynamic content inside each page, the flipping effect becomes very shaky...

So now I'm implementing my own flipping effect with css and javascript..

The page structure is like this

<div class="page" id="page1">
    <div class="inner"></div>
</div>
<div class="page" id="page2">
    <div class="inner"></div>
</div>

When the flipping is triggered... I did the following... BUT I find it not elegant because its supposed to be a smooth 180 rotation rather than breaking the action into two.. the problem I have is the z-index.. after rotating -90deg, I want the "back" page to show on top otherwise it will be always the "front" side...

    var front = '<div class="front" style="clip: rect(0px, 2229px, 1315px, 1115px);">' + $('#page2').children('.megafolio-container').html() + '</div>';
    var back = '<div class="back megafolio-container" style="clip: rect(0px, 2229px, 1315px, 1115px);">' + $('#page3').children('.megafolio-container').html() + '</div>';
    var middle = '<div class="middle page"></div>';
    $('.container').append(middle);
    $('.middle').html(front + back);
    $('.middle').height($(window).height());
    $('.middle').width($(window).width());
    $('.middle').css('-webkit-transform', 'rotateY(-90deg)');
    $('.middle').css('-webkit-transition', '-webkit-transform 500ms linear');
    setTimeout(function(){
        $('.middle > .back').css('z-index', 10);
        $('.middle').css('-webkit-transform', 'rotateY(-180deg)');
        $('.middle').css('-webkit-transition', '-webkit-transform 500ms linear');
    }, 500);

Answer

user2719890 picture user2719890 · Mar 4, 2015

Try this "Turnjs" it is a simple Javascript API which enables the flip page effect:

Turnjs

It is very easy to use and one simple example as given in the website is this:

<div id="flipbook">
<div class="hard"> Turn.js </div>
<div class="hard"></div>
<div> Page 1 </div>
<div> Page 2 </div>
<div> Page 3 </div>
<div> Page 4 </div>
<div class="hard"></div>
<div class="hard"></div>

<script type="text/javascript">
    $("#flipbook").turn({
        width: 400,
        height: 300,
        autoCenter: true
    });
</script>