Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrollTo not scrolling the window

I am not sure why this isn't working

html

    <a href="#" id="scrollTop" class="margin-top-40 btn btn-danger btn-lg top btn-not-100">Back to top</a>

jQuery

    $("#scrollTop").on("click",function(e){
      e.preventDefault();
      $(window).animate({scrollTop: 0}, 'slow');
    });

Even tried the following with still negative results

    $("#scrollTop").on("click",function(e){
      e.preventDefault();
      $("body, html").animate({scrollTop: 0}, 'slow');
    });

Css

    html, body {height:100%;}

Using jquery-1.10.2.js, consolle not giving any error

UPDATE Comments below lead me to understand the issue is with using jQuery scrollTop and html, body set to overflow... Because of that a new question has been created here on stack.

like image 513
rob.m Avatar asked Oct 21 '22 16:10

rob.m


1 Answers

Got the issue, thanks to comments I noticed I had body: overflow-x:hidden which means scrollTop isn't working when we are using overflow on body, html

like image 114
rob.m Avatar answered Oct 23 '22 15:10

rob.m