Newer
Older
dmpopidor / app / javascript / utils / scrollTo.js
@Bodacious Bodacious on 19 Oct 2018 499 bytes Update asset structure with webpacker gem
import { isString, isNumber } from './isType';

/*
  Scrolls browser window to the selector specified
  @param selector - String CSS selector
  @param duration (optional) - Number or String that determines how long the animation will run
*/
export const scrollTo = (selector, duration) => {
  if (isString(selector)) {
    $('html, body').animate({
      scrollTop: $(selector).offset().top,
    }, isNumber(duration) || isString(duration) ? duration : 500);
  }
};

export { scrollTo as default };