1

I've built a HTML webpage with some JavaScript code for a smooth user experience. However, the scroll JavaScript function does not work anymore if I add the load JavaScript function to my webpage.

The load script is just below the body tag. I've tried placing the scroll script inside the head tag and in the body tag but doesn't seem to work anywhere is the scroll script present.

Scroll script:

<script type="text/javascript">
    $(document).ready(function(){
          $("a").on('click', function(event) {
            if (this.hash !== "") {
              event.preventDefault();
              var hash = this.hash;
              $('html, body').animate({
                scrollTop: $(hash).offset().top
              }, 600, function(){
                window.location.hash = hash;
              });
            } 
          });
        });
</script>

Load script:

<div class="se-pre-con"></div>
<script type="text/javascript">
    $(window).load(function() {
    $(".se-pre-con").fadeOut("slow");;
    });
</script>
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
James Miller
  • 121
  • 2
  • 12
  • Possible duplicate of [jQuery animate scroll](https://stackoverflow.com/questions/8047454/jquery-animate-scroll) – Rainbow Apr 30 '19 at 20:41

1 Answers1

0

You probably upgraded from jQuery 2.x to 3.x

change

$(window).load(function() {

to

$(window).on("load", function (e) {

and you should be fine.

Nosajimiki
  • 1,073
  • 1
  • 9
  • 17