Uncaught error trying to use smooth scroll


#1

I’ve added the suggested code to the page to allow elements to scroll to specific areas of the page, and I’ve set up the buttons with the correct #anchor elements. This is the code I used:

<script>
  lp.jQuery(function($) {
  
// The speed of the scroll in milliseconds
var speed = 1000;
  
// Find links that are #anchors and scroll to them
$('a[href^=#]')
  .not('.lp-pom-form .lp-pom-button')
  .unbind('click.smoothScroll')
  .bind('click.smoothScroll', function(event) {
    event.preventDefault();
    $('html, body').animate({ scrollTop: $( $(this).attr('href') ).offset().top }, speed);
  });
  });
</script>

However when I click the buttons nothing happens and there is an error in the console that says
Uncaught TypeError: Cannot read property ‘top’ of null


#2

Hi @irvineinteractive,

Are you loading the right jQuery library before the smooth scroll script?

It would be helpful if you share the actual landing page URL so we can take a look.

Best,
Hristian


#3

Hello,
I am not explicitly loading any jquery libraries but the Unbounce page has them on there.

Do I need to load the jquery.smooth-scroll.js on my page?