Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Go to an element on page using jQuery.
- ```js
- // @params
- // ms - milliseconds
- // top - padding from top after scrolling to the element
- (function(jQuery) {
- jQuery.fn.goTo = function(ms, top) {
- if (top == null) {
- top = 10;
- }
- $('html, body').animate({
- scrollTop: $(this).offset().top - top + 'px'
- }, ms);
- return this;
- };
- })(jQuery);
- ```
- Usage
- ```js
- $(selector).goTo(500);
- $(selector).goTo(500, 10);
- ```
Add Comment
Please, Sign In to add comment