JAVASCRIPT
Scroll to content
All samples are using Ink.requireModules
, please read how to use it at Ink.requireModules section
Function name | Description |
---|---|
.init([selector]) | Has smooth scrolling applied to relevant elements upon page load. |
.scroll(scrollTop, options) | Moves the scrollbar to the target element. This is the function |
Property name | Description |
---|---|
.changeHash | Change the URL hash (location.hash) when done scrolling? Defaults to true. |
.margin | The default top margin. |
.speed | The default scrolling speed. Higher is slower. Defaults to 10. |
Has smooth scrolling applied to relevant elements upon page load.
Listens to the click event on the document.
Anything which matches the selector will be considered a "link" by SmoothScroller and handled as such.
When a link is clicked, it is checked for several options:
data-margin="0"
- A margin in pixels -- useful when you have a position:fixed top bar.data-speed="10"
- Inverse speed of the scrolling motion. Smaller is faster.data-change-hash="true"
- Change the URL hash (location.hash) when done scrolling.selector
'a.scrollableLink,a.ink-smooth-scroll'Selector string for finding links with smooth scrolling enabled.Demo
Code
Moves the scrollbar to the target element. This is the function
which animates the scroll position bit by bit. It calls itself in
the end through requestAnimationFrame
scrollTop
Y coordinate value to stop atoptions
Option hash containing:options.margin
Set this to non-zero to leave a margin between the top of the page and your element. Useful if you have a top bar with `position: fixed`.options.speed
Inverse scrolling speed. Smaller is faster.Boolean
Change the URL hash (location.hash) when done scrolling? Defaults to true.
Number
The default top margin.
Use this when you want the scroll motion to stop before it reaches its destination, for example when you want to add some breathing space or have a position:fixed top bar in front of your content.
Number
The default scrolling speed. Higher is slower. Defaults to 10.