There might be a cleaner way to do this, but this seems to work:
Edit fiddle - JSFiddle[
^]
Change the styles:
.page-holder {
position: relative;
}
.page {
position: absolute;
top: 0;
left: 0;
width: 100%;
transform: translate(0, 0);
}
.page.animate {
transition: transform 0.6s ease-in;
}
.page.left {
transform: translate(-100%, 0);
}
.page.right {
transform: translate(100%, 0);
}
Add the class
right
to all pages except the first:
container.find('.page:not(:first-child)').addClass('right');
Or you could do this in the markup.
Set the height for the
page-holder
, since I can't find a way in CSS to make it encompass absolutely-positioned children:
var maxHeight = 0;
var container = $('.page-holder');
container.find('.page').each(function(){
maxHeight = Math.max(maxHeight, $(this).height());
});
container.height(maxHeight);
Change the
else
block in the
currentPageIndex
change watcher:
else {
var allPages = container.find('.page').removeClass('animate left right');
allPages.eq(oldVal).addClass('animate');
var newPage = allPages.eq(newVal).addClass('animate');
newPage.prevAll('.page').addClass('left');
newPage.nextAll('.page').addClass('right');
}
And now the pages "hop" correctly. :)