Skip to content

Instantly share code, notes, and snippets.

@jljorgenson18
jljorgenson18 / gist:d05d21e034de987e569a
Last active August 29, 2015 14:18
Finds an element using an id or a css class and smoothly scrolls to that element. Duration of the animation depends on scroll position. Based off of a stackoverflow answer by bfred.it at http://stackoverflow.com/questions/21474678/scrolltop-animation-without-jquery . NOTE: This only works for scrolling "up" to an element at the moment. The extra…
var scrollTo = function(id, cls, offset) {
var ele;
var targetOffset = 0;
var targetTop = 0;
if(offset) {
targetOffset = offset;
}
if(id) {
ele = document.getElementById(id);