Advertisement
borlabs

Scroll to

Mar 18th, 2019
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function ($) {
  2.  
  3.     "use strict";
  4.    
  5.     $(document).ready(function () {
  6.          /* Scroll to */
  7.         $("a[href^='#']").click(function (e) {
  8.        
  9.             if ($(this).attr("href") !== "#!" && $($(this).attr("href")).length) {
  10.        
  11.                 e.preventDefault();
  12.        
  13.                 var additionalSpace = 20;
  14.        
  15.                 // Header bar when already scrolled
  16.                 if ($(".masthead").length) {
  17.                     additionalSpace += $(".masthead").height();
  18.                 }
  19.        
  20.                 // If user is logged-in
  21.                 if ($("#wpadminbar").length) {
  22.                     additionalSpace += $("#wpadminbar").height();
  23.                 }
  24.        
  25.                 $("html, body").animate({
  26.                     scrollTop: $($(this).attr("href")).offset().top - additionalSpace
  27.                 }, 500);
  28.             }
  29.         });
  30.     });
  31. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement