I'm trying to build an effect like this for smoothstate: http://tympanus.net/Development/PageTransitions/, specifically the "room" transitions.
I'm getting stuck on trying to display both pages at once - I want the new content to push the old off the screen.
lots of code follows...it all works, but it waits until after the old content is offscreen to start adding new content
$(function(){
'use strict';
var options = {
prefetch: true,
cacheLength: 10,
onStart: {
duration: 500, // Duration of our animation
render: function ($container) {
// scroll up
$("html, body").animate({ scrollTop: "0px" });
var element = $('.row', $container);
// do animations
$(element).animate({opacity : 0}, {
duration: 500,
easing: "linear",
step: function(number, tween) {
number = 1 - number;
var element = document.getElementsByClassName('row')[0];
element.style.transform = "translateX(-" + 45*number + "%) rotateY(" + 90*number + "deg)";
}
});
}
},
onReady: {
duration: 500,
render: function ($container, $newContent) {
// Inject the new content
$container.html($newContent);
$container.css({overflow : 'hidden'});
// do animations
var element = document.getElementById($container[0].id).getElementsByClassName('row')[0];
element.style.opacity = 0;
$(element).animate({opacity : 1}, {
duration: 500,
step: function(number, tween) {
number = 1 - number;
var element = document.getElementsByClassName('row')[0];
element.style.transform = "translateX(" + 45*number + "%) rotateY(-" + 90*number + "deg)";
}
});
}
}
},
smoothState = $('#main').smoothState(options).data('smoothState');
});
I would have though that changing the onStart
duration to be shorter than the animation duration would work, but it just cuts the animation short, leaving a blank screen.
I'm aware that $container
is used for both, but I believe I can fix that with $container.clone();
to hold the old content while it moves off the page.
My question: is there a way to access $newContent other than waiting for onStart
to complete?
Note: the same behavior occurs with CSS animations - they terminate at the end of onStart
.