Created
June 27, 2014 06:49
-
-
Save fullpipe/8cb31e6cd185455c2abd to your computer and use it in GitHub Desktop.
Scroll page to specific 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
$(document).ready(function() { | |
"use strict"; | |
$.fn.scrollToMe = function(force) { | |
var | |
force = force || false, | |
elemOffset = $(this).offset(), | |
$bodyElem = $.browser.safari ? $("body") : $("html"), | |
topScroll = +$bodyElem.scrollTop(), | |
windowHeight = $(window).height() | |
; | |
if (!force) { | |
if (elemOffset.top > topScroll && elemOffset.top < (topScroll + windowHeight)) { | |
return false; | |
}; | |
}; | |
$bodyElem.animate({ | |
scrollTop: elemOffset.top | |
}, 'fast'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$('#menu').scrollToMe();