Linked Javascript File Isn't Working in Child Theme

The script is a simple smooth scroll effect for internal page anchors. It works on our live site that has a different theme, but not in staging where we are switching to Pro.

Examples:
Staging Site (not working)
Live Site (working)

Click the page links at the top and see how the smooth scroll effect is working on live, but not on staging.

The external script is linked in the footer in both cases (general.js located in the child theme folder). We also had this same problem on the homepage when trying to use a jQuery script called Paroller. You can see it in the footer as well (jquery.paroller.js), but the script didn’t actually work until we linked it internally Visual Composer’s Raw JS module.

Hello There,

Thanks for writing in! The external script is not working because it has some errors in it.

Please have it updated and make use of this code instead:

(function($)){
  $(document).ready(function(){
    $('a[href^="#"]').on('click',function (e) {
        e.preventDefault();

        var target = this.hash;
        var $target = $(target);

        $('html, body').stop().animate({
            'scrollTop': $target.offset().top
        }, 900, 'swing', function () {
            window.location.hash = target;
        });
    });
  });
   if ( matchMedia("(min-width: 991px)").matches ) {

  $('a[href^="#"]').not($(".vc_tta a")).on('click', function(e) {
      var hash  = this.hash,
        $hash = $(hash),
          addHash = function() {
              window.location.hash = hash;
          };

      if ( hash !== '#header' ) {
          // $hash.velocity('scroll', { duration: 500, offset: -50, complete: addHash }); // Velocity.js
          $('html,body').animate({ 'scrollTop': $hash.offset().top -150 }, 700, addHash);
      } else {
          // $hash.velocity('scroll', { duration: 500, offset: 0, complete: addHash }); // Velocity.js
          $('html,body').animate({ 'scrollTop': $hash.offset().top }, 700, addHash);
      }
      e.preventDefault();
  });
   }
   if ( matchMedia("(min-width: 600px)").matches ) {

  $('a[href^="#"]').not($(".vc_tta a")).on('click', function(e) {
      var hash  = this.hash,
        $hash = $(hash),
          addHash = function() {
              window.location.hash = hash;
          };

      if ( hash !== '#header' ) {
          // $hash.velocity('scroll', { duration: 500, offset: -50, complete: addHash }); // Velocity.js
          $('html,body').animate({ 'scrollTop': $hash.offset().top -140 }, 700, addHash);
      } else {
          // $hash.velocity('scroll', { duration: 500, offset: 0, complete: addHash }); // Velocity.js
          $('html,body').animate({ 'scrollTop': $hash.offset().top }, 700, addHash);
      }
      e.preventDefault();
  });
   }
   else {

  $('a[href^="#"]').not($(".vc_tta a")).on('click', function(e) {
      var hash  = this.hash,
        $hash = $(hash),
          addHash = function() {
              window.location.hash = hash;
          };

      if ( hash !== '#header' ) {
          // $hash.velocity('scroll', { duration: 500, offset: -50, complete: addHash }); // Velocity.js
          $('html,body').animate({ 'scrollTop': $hash.offset().top -40 }, 700, addHash);
      } else {
          // $hash.velocity('scroll', { duration: 500, offset: 0, complete: addHash }); // Velocity.js
          $('html,body').animate({ 'scrollTop': $hash.offset().top }, 700, addHash);
      }
      e.preventDefault();
  });
 }
})(jQuery); 

Please let us know if this works out for you.

Had to make one minor change (removing one closing parenthesis from line 1), but now it works!

Thank you so much! :slight_smile: By the way, this theme is an amazing improvement from the already awesome X theme. We are very happy with it and all of your support has been amazing. Keep up the good work!

Hello There,

You’re most welcome! We are just glad we were able to help you out.
Thanks for letting us know that it has worked for you.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.