Guest User

Untitled

a guest
Feb 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. Go to an element on page using jQuery.
  2.  
  3. ```js
  4. // @params
  5. // ms - milliseconds
  6. // top - padding from top after scrolling to the element
  7. (function(jQuery) {
  8. jQuery.fn.goTo = function(ms, top) {
  9. if (top == null) {
  10. top = 10;
  11. }
  12. $('html, body').animate({
  13. scrollTop: $(this).offset().top - top + 'px'
  14. }, ms);
  15. return this;
  16. };
  17. })(jQuery);
  18. ```
  19.  
  20. Usage
  21.  
  22. ```js
  23. $(selector).goTo(500);
  24. $(selector).goTo(500, 10);
  25. ```
Add Comment
Please, Sign In to add comment