Thanks for the reply and the links. I'll definately read these articles.
I'm using HTML5 history and everything is triggered when the URL changes. I've made everything to work but there is a part that I don't like. I think my solution is a little bit dirty. I'm not very experienced
I'm not using the ajax beforeSend anymore. I couldn't find a way to wait for the animations to finish and then load the new content. So instead
I have an outro sequence,
Then I load with ajax the new elements,
I hide the new content (this is what I don't like)
Reveal everything (intro sequence)
My code so far:
$window.bind('statechange',function(){
sequenceOut();
function sequenceOut(){
tl.to("#main", 1, {scaleY:"0", ease:Power4.easeInOut});
tl.to("#bg-img", 1, {opacity:"0", ease:Power4.easeInOut}, "-=1.0");
tl.call(loadPage);
}
function sequenceIn(){
// hide specific elements when new page loads
tl.to("#bg-img", 0, {opacity:"0"});
tl.to("#main", 0, {scaleY:"0"});
// reveal elements sequentially
tl.to("#bg-img", 1, {opacity:"1", ease:Power4.easeInOut});
tl.to("#main", 0.8, {scaleY:"1", ease:Power4.easeInOut}, "-=0.8");
}
function loadPage(){
// ajax loads and callbacks here
success: calls the sequenceIn function
}
});
The part that I don't like is that I have to hide some elements by default after the ajax load and then reveal them again with timeline animations. Any suggestions would be very welcome.
Thanks again.