@bolt/components-smooth-scroll
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"sourceFilesFrom": "0.9.5", | ||
@@ -14,0 +14,0 @@ "maintainers": [ |
@@ -5,9 +5,9 @@ import SmoothScroll from 'smooth-scroll'; | ||
const defaultScrollOffset = 0; | ||
const defaultScrollSpeed = 500; | ||
const defaultScrollOffset = 45; | ||
const defaultScrollSpeed = 750; | ||
const customScrollElems = document.querySelectorAll('a[href*="#"]'); | ||
customScrollElems.forEach(elem => { | ||
const scrollElem = elem; | ||
const scrollSpeed = defaultScrollSpeed; | ||
const customScrollElems = document.querySelectorAll('a[href^="#"]'); | ||
for (var i = 0, len = customScrollElems.length; i < len; i++) { | ||
const scrollElem = customScrollElems[i]; | ||
const scrollSpeed = defaultScrollSpeed; | ||
@@ -18,29 +18,30 @@ // In the future, we could add support for links to modify options like scrollOffset, scrollOffset, etc. However, | ||
// | ||
const scrollOffset = scrollElem.dataset.scrollOffset ? scrollElem.dataset.scrollOffset : defaultScrollOffset; | ||
const scrollOffset = scrollElem.dataset.scrollOffset ? scrollElem.dataset.scrollOffset : defaultScrollOffset; | ||
// const scrollSpeed = scrollElem.dataset.scrollSpeed ? scrollElem.dataset.scrollSpeed : defaultScrollSpeed; | ||
const scrollOptions = { | ||
ignore: '[data-scroll-ignore]', // Selector for links to ignore (must be a valid CSS selector) | ||
header: '.js-bolt-smooth-scroll-offset', // Selector for fixed headers (must be a valid CSS selector) | ||
const scrollOptions = { | ||
ignore: '[data-scroll-ignore]', // Selector for links to ignore (must be a valid CSS selector) | ||
header: '.js-bolt-smooth-scroll-offset', // Selector for fixed headers (must be a valid CSS selector) | ||
// Speed & Easing | ||
speed: scrollSpeed, // Integer. How fast to complete the scroll in milliseconds | ||
offset: scrollOffset, // Integer or Function returning an integer. How far to offset the scrolling anchor location in pixels | ||
easing: 'easeInOutCubic', // Easing pattern to use | ||
speed: scrollSpeed, // Integer. How fast to complete the scroll in milliseconds | ||
offset: scrollOffset, // Integer or Function returning an integer. How far to offset the scrolling anchor location in pixels | ||
easing: 'easeInOutCubic', // Easing pattern to use | ||
// Callback API | ||
before: function () {}, // Callback to run before scroll | ||
after: function () {}, // Callback to run after scroll | ||
}; | ||
// Callback API | ||
before () {}, // Callback to run before scroll | ||
after () {}, // Callback to run after scroll | ||
}; | ||
let scrollElemHref = scrollElem.getAttribute('href'); | ||
scrollElemHref = scrollElemHref.replace('#', ''); | ||
let scrollElemHref = scrollElem.getAttribute('href'); | ||
scrollElemHref = scrollElemHref.replace('#', ''); | ||
const scrollTarget = document.getElementById(scrollElemHref); | ||
const scrollTarget = document.getElementById(scrollElemHref); | ||
if (scrollTarget) { | ||
scrollElem.addEventListener('click', function(){ | ||
scroll.animateScroll(scrollTarget, scrollElem, scrollOptions); | ||
}); | ||
} | ||
}); | ||
if (scrollTarget) { | ||
scrollElem.addEventListener('click', function(event){ | ||
event.preventDefault(); | ||
scroll.animateScroll(scrollTarget, scrollElem, scrollOptions); | ||
}); | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37
3777