Search code examples
meteoriron-router

Meteor + Iron Router unable to scroll up


I have tried using command like scrollTo(0) and packages like okgrow:router-autoscroll. I have read through many pages online. I am completely unable to make it so that when I load a new template via route (Iron Router) it automatically scrolls to the top.

Edit: I have tried all of the following to no avail:

$(window).scrollTop()
$('body, html').scrollTop()
$('body').scrollTop()
$(document).scrollTop()
window.scrollTo(x, y)

Solution

  • For those of you with the same issue. I ended up solving this with problem in all browsers with the following code:

    Template.templateName.onRendered(function(){
        $('.wrapper-header')[0].scrollIntoView();
    });
    

    This should work in all browsers as it did for me, and remove the necessity for flowrouter and Iron Router autoscroll addons.

    Hope this helps!