I have just discovered Barba.js and find it very useful. It provides smooth transitions between URLs of the same website.
I have put together a Plunker consisting of two pages (index.html and about.html) that are loaded smoothly, with the help of jQuery’s fadeIn()
and fadeOut()
methods.
$(document).ready(function() {
var transEffect = Barba.BaseTransition.extend({
start: function() {
this.newContainerLoading.then(val => this.fadeInNewcontent($(this.newContainer)));
},
fadeInNewcontent: function(nc) {
nc.hide();
var _this = this;
$(this.oldContainer).fadeOut(1000).promise().done(() => {
nc.css('visibility', 'visible');
nc.fadeIn(1000, function() {
_this.done();
});
$('html, body').animate({
scrollTop: 300
},1000);
});
}
});
Barba.Pjax.getTransition = function() {
return transEffect;
}
Barba.Pjax.start();
});
The problem with this animations is that there is a white screen interval between them.
How could I eliminate this interval, to make the transition smoother? By "smoother" I mean similar to this one (click "view case").
I came out with this version of the script:
It is better, but not smooth enough. See the the effect on a real life project. How can I improve it?
How about using
setTimeout()
to overlap the fade out and fade in? That should keep it from blanking out completely, which want to avoid.You could try something like the following:
NOTE: This is just a stab at it, the plunker is helpful, but it's hard to see the animation in action.
UPDATE
I think you'll need something like the above, but if you want to fade in/out of black, then you'll also want to do something like create a div wrapper around all of your content within your body and give that div the background color of your app, #eff3f6, and then making the actual body background black. You'll have some work to get the exact effect you desire, but something like that or in the SO link in the comments below should help.
The white screen is the body color because you're using
promise().done(..)
jquery
apply thefadeIn
after thefadeOut
finish so the body color will appear. So, this is an example sort of similar to what you have:like you see in the example above the white screen also appears so if you don't want that just don't use
promise().done(..)
.you can edit your code like this: