Guest User

Untitled

a guest
May 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. $(function() {
  2. $("a[href^=#]").scrollToAnchor(); // scroll to any link at default speed
  3. $("a.slowerScroll").scrollToAnchor({ speed: 2000 }); // scroll to links with class slowerScroll at half speed
  4. });
  5.  
  6. jQuery.fn.scrollToAnchor = function(settings) {
  7. settings = jQuery.extend({ speed : 1000 }, settings);
  8.  
  9. return this.each(function() {
  10. var self = $(this);
  11. self.click(function(e) {
  12. e.preventDefault();
  13. var href = self.attr("href");
  14. var target = $(href).offset().top;
  15. $("html:not(:animated), body:not(:animated)").animate({ scrollTop: target }, settings.speed, function() {
  16. window.location.hash = href;
  17. });
  18. return false;
  19. });
  20. });
  21. };
Add Comment
Please, Sign In to add comment