Created
March 21, 2014 10:02
-
-
Save itsjavi/9683028 to your computer and use it in GitHub Desktop.
Soft scroll to an element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.skrollto = function(speed, easing) { | |
speed = speed || 1000; | |
easing = easing || 'swing'; | |
return $(this).each(function(i, el){ | |
//calculate destination place | |
var dest = 0; | |
var el = $(this); | |
if (el.is(':hidden')) { | |
el.show(); | |
} | |
if (el.offset().top > $(document).height() - $(window).height()) { | |
dest = $(document).height() - $(window).height(); | |
} else { | |
dest = el.offset().top; | |
} | |
//go to destination | |
$('html,body').animate({ | |
scrollTop: dest | |
}, speed, easing); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment