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.
I would like the About us page to not only be faded in, but scrolled down some 250px too.
For this purpose, I have:
- added a class to the html tag in the About Us page:
<html class="about">
added this in the script.js:
$('html.about, html.about body').animate({ scrollTop: 300 },1000);
Evan though the page scrolls if no class name selector is mentioned in the script, the version above does not work. But I want only the "About Us" page to be animated.
What shall I change?
The "About Us" page and the index page are displayed on the same page, a new html document is not rendered for each page. The content of each page is simply written over the previous one, ie inside the
.barba-wrapper
div element. So scrolling the page of one is going to "scroll the other one" as they are on the same page.The
<html>
element stays the same between page switches, it never gets a classabout
. This is why your selector doesn't work to scroll the page.If you want the page to be back at the top when going back simply animate it back to the top on Barba changing it. You can do this by: