HubSpot/shepherd — pull request #5 by cmalven (2014-03-13 18:35:26+00:00)
Title: Adds a scrollToMethod option to Shepherd Defaults.

We're using Shepherd to implement our onboarding process, and we found that the default `scrollTo` method used by Shepherd was a jarring experience for longer pages.

We discussed various ways to implement smoother scrolling for Shepherd, and decided that the ability to specify a custom `scrollToHandler` could be a valuable addition for everyone using Shepherd.

The handler can be passed to a tour during creation, like so:

```coffeescript
myTour = new Shepherd.Tour
defaults:
scrollTo: true
scrollToMethod: (el) ->
# myScrollUtility.scrollTo($(el).offset().top
```

Shepherd's internal `scrollTo` function simply looks for a custom `scrollToMethod` and if found fires it on the element. If no `scrollToMethod` is found it defaults to its current `scrollIntoView()` call.

**Note:** `scrollTo` must be `true` in addition to setting a custom `scrollToMethod`.

If you're curious, this is how Desktime is currently using this:

```coffeescript
#= require jquery.scrollTo
#= require jquery.easing.1.3

introTour = new Shepherd.Tour
defaults:
scrollTo: true
scrollToMethod: (el) ->
winHeight = $(window).height()
bodyHeight = $('body').height()
maxScrollPos = bodyHeight - winHeight
targetPos = $(el).offset().top - winHeight / 2
if targetPos < 0
targetPos = 0
if targetPos > maxScrollPos
targetPos = maxScrollPos
$(window).scrollTo targetPos, 1000, {easing:'easeOutQuart'}
```

This places the targeted content neatly near the center of the viewport.