Files
openfoodnetwork/app/assets/javascripts/darkswarm/directives/smooth_scroll_to.js.coffee
Matt-Yorkley bd97939062 Move homepage "register here" CTA to bottom of screen.
The CTA breaks the layout when the new cart sidebar is open. I can't see a nice way to keep it at the top without making a mess.
2020-06-18 22:21:55 +02:00

15 lines
622 B
CoffeeScript

Darkswarm.directive "ofnSmoothScrollTo", ($location, $document)->
# Onclick sets $location.hash to attrs.ofnScrollTo
# Then triggers $document.scrollTo
restrict: 'A'
link: (scope, element, attrs)->
element.bind 'click', (ev)->
ev.stopPropagation()
$location.hash attrs.ofnScrollTo
target = $("a[name='#{attrs.ofnSmoothScrollTo}']")
# Scrolling is confused by our position:fixed top bar and page alert bar
# - add an offset to scroll to the correct location, plus 5px buffer
offset = $("nav.top-bar").height()
offset += 5
$document.scrollTo target, offset, 1000