Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add scrollto parameters #4

Merged
merged 3 commits into from
Feb 16, 2022
Merged

Conversation

robiseb
Copy link
Contributor

@robiseb robiseb commented Feb 16, 2022

Fix issue #3

  • Able to add parameters to the data-scrollto

Scroll to

Internally use jump.js library.

Listen jump link [data-scrollto] elements:

<div data-scrollto="#top">content</div>

Jump programmaticaly to an element:

import { scrollTo } from '@wide/scroll'

scrollTo('.something')

You can define global config applying to all links:

import { JUMP_CONFIG } from '@wide/scroll'

JUMP_CONFIG.offset = -20 // top offset for all jump

You can aslo define config locally by adding HTML attributes:

<button
  data-scrollto="#footer"
  data-scrollto.duration="1010"
  data-scrollto.offset="0"
  data-scrollto.a11y="false"
  data-scrollto.callback="scrollToCallback"
  data-scrollto.easing="scrollToEasing"
>
  Scroll to footer
</button>
window.scrollToCallback = () => {
  // Do some stuffs when scroll has been completed
}

window.scrollToEasing = () => {
  // My custom easing animation code
}

Note: Those parameters will override default (global) parameters.

Parameters

Name Type Description Default value
duration number Pass the time the scrollto() takes, in milliseconds. 800
offset number Offset a scrollto(), only if to an element, by a number of pixels. -80
a11y boolean If enabled, and scrolling to an element: add a tabindex to, and focus the element true
callback function Pass a function that will be called after the scrollto() has been completed. null
easing function Easing function used to transition the scrollto(). null

More informations on Jump.js documentation.

@robiseb robiseb merged commit 13b96df into develop Feb 16, 2022
@robiseb robiseb deleted the feature/3-add-scrollto-parameters branch February 16, 2022 14:15
robiseb added a commit that referenced this pull request Feb 16, 2022
* Fix issue #3
* Some improvements
* Readme updated
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant