Add Scroll to top before transition start
See original GitHub issueJs newbie here, so excuse moi the dumb question ;D
Trying to add scrollTop before the transition start in the fade example below (got it on http://barbajs.org/transition.html). Right now this code works but the new page opens on random content.
var FadeTransition = Barba.BaseTransition.extend({
start: function() {
/**
* This function is automatically called as soon the Transition starts
* this.newContainerLoading is a Promise for the loading of the new container
* (Barba.js also comes with an handy Promise polyfill!)
*/
// As soon the loading is finished and the old page is faded out, let's fade the new page
Promise
.all([this.newContainerLoading, this.fadeOut()])
.then(this.fadeIn.bind(this));
},
fadeOut: function() {
/**
* this.oldContainer is the HTMLElement of the old Container
*/
return $(this.oldContainer).animate({ opacity: 0 }).promise();
},
fadeIn: function() {
/**
* this.newContainer is the HTMLElement of the new Container
* At this stage newContainer is on the DOM (inside our #barba-container and with visibility: hidden)
* Please note, newContainer is available just after newContainerLoading is resolved!
*/
var _this = this;
var $el = $(this.newContainer);
$(this.oldContainer).hide();
$el.css({
visibility : 'visible',
opacity : 0
});
$el.animate({ opacity: 1 }, 400, function() {
/**
* Do not forget to call .done() as soon your transition is finished!
* .done() will automatically remove from the DOM the old Container
*/
_this.done();
});
}
});
/**
* Next step, you have to tell Barba to use the new Transition
*/
Barba.Pjax.getTransition = function() {
/**
* Here you can use your own logic!
* For example you can use different Transition based on the current page or link...
*/
return FadeTransition;
};
any idea??
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Results From Across the Web
react-router scroll to top on every transition - Stack Overflow
I have an issue when navigating into another page, its position will remain like the page before. So it won ...
Read more >How to Make an Unobtrusive Scroll-to-Top Button | CSS-Tricks
A button to return to the top of the page allows the user to quickly return to the top of the page without...
Read more >How to Make a Back to Top Button and Page Progress Bar ...
How to scroll to top whenever the user clicks the Back To Top Button ... The scrollIntoView() (MDN Reference) function scrolls the page...
Read more >Pure CSS Smooth-Scroll "Back to Top "
We also add id="top" to the <header> and use that anchor as the href value for the back to top link. If you...
Read more >How To Make a Cool Animated Scroll-to-Top Button - Anyday Inc
Let's first hide this button by adding margin-bottom: -12rem; to hide the button. We'll also add a transition: margin-bottom 0.2s; to ensure that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I also recommend adding this too:
What this does is it prevent Chrome from jumping to the last scroll position when pressing the back button. Without it, even when scrolling to the top of the page with jquery Chrome will remember the last scroll position causing issues with your animation.
@yelapijo You can scroll to the top of the page before the fade in like this:
As long as you put
$(window).scrollTop(0);
before the animate function you should be fine.