0

I'm trying to fix so that when i press on a link on my website the new "page" will open at the top.

Trided something like this:

$(function() {
  if ($(window).scrollTop() < ($(".pageWrapper").offset().top - 110)) {
    $('html, body').animate({ scrollTop: $(".pageWrapper").offset().top - 110 }, 2000);
                }
            });

But didn't rlly work.

Any ideas? ... haha

ekonomisten
  • 1
  • 1
  • 3
  • 1
    Possible duplicate of [Scroll to the top of the page using JavaScript/jQuery?](https://stackoverflow.com/questions/1144805/scroll-to-the-top-of-the-page-using-javascript-jquery) – Milan Chheda May 30 '17 at 10:31

3 Answers3

0

Alright try this

$(function(){
  $('body,html').animate({
    scrollTop : 0   // 0 means top,change it to 110 for offset                  
  }, 500);
});

Hope this Helps.

Krunal Limbad
  • 1,533
  • 1
  • 12
  • 23
0

this s pure js solution you can choose any one

document.body.scrollTop = document.documentElement.scrollTop = 0;

or

you almost got it - you need to set the scroll Top on body, not window:

$(function() {
   $('body').scrollTop(0);
  });
Mafas Deen
  • 87
  • 1
  • 13
Always Learn
  • 662
  • 6
  • 14
0

Try this:

$(function() {
     $('html, body').animate({ 
         scrollTop: 0
     }, 2000);
  return false
 });
SilverSurfer
  • 4,281
  • 6
  • 24
  • 50