Advertisement
Guest User

functions.php

a guest
Jul 29th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. function smoothscroll_script() { ?>
  2. <script>
  3. jQuery(document).ready(function($) {
  4.  
  5. $('a[href^="#"][href!="#"], .smoothscroll, .smoothscroll a').click(function(e) {
  6. e.preventDefault();
  7. e.stopPropagation();
  8. var url = $(this).attr('href'),
  9. hash = url.substring(url.indexOf('#'));
  10.  
  11. scrollTo(hash);
  12.  
  13.  
  14.  
  15. });
  16.  
  17. });
  18.  
  19. jQuery(window).load(function($) {
  20. if (window.location.hash)
  21. scrollTo(window.location.hash);
  22. });
  23.  
  24. function scrollTo(hash) {
  25.  
  26. var offset = jQuery(hash).offset().top,
  27. headerHeight = 50,
  28. wpAdminBarHeight = jQuery('html').css("margin-top").replace(/[^-\d\.]/g, '');
  29.  
  30. jQuery('html, body').stop().animate({
  31. scrollTop: (offset - headerHeight - wpAdminBarHeight)
  32. }, 1500,'easeInOutExpo', function() { window.location.hash = "" + hash; });
  33.  
  34.  
  35. }
  36. </script>
  37. <?php
  38. }
  39.  
  40. add_action( 'wp_footer', 'smoothscroll_script' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement