x
This commit is contained in:
1 parent
b693c7188c
commit
9941798a85
2 files changed
+33
-2
No files matched your search
@@ -72,10 +72,20 @@ export default function ProductStickyPurchaseBar({
|
||||
const trigger = document.getElementById(triggerId)
|
||||
if (!trigger) {
|
||||
setIsVisible(false)
|
||||
if (document.documentElement.dataset.productStickyVisible !== 'false') {
|
||||
document.documentElement.dataset.productStickyVisible = 'false'
|
||||
window.dispatchEvent(new CustomEvent('product-sticky-change', { detail: false }))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
setIsVisible(trigger.getBoundingClientRect().top <= 0)
|
||||
const nextVisible = trigger.getBoundingClientRect().top <= 0
|
||||
setIsVisible(nextVisible)
|
||||
const nextStr = nextVisible ? 'true' : 'false'
|
||||
if (document.documentElement.dataset.productStickyVisible !== nextStr) {
|
||||
document.documentElement.dataset.productStickyVisible = nextStr
|
||||
window.dispatchEvent(new CustomEvent('product-sticky-change', { detail: nextVisible }))
|
||||
}
|
||||
}
|
||||
|
||||
updateVisibility()
|
||||
@@ -83,6 +93,8 @@ export default function ProductStickyPurchaseBar({
|
||||
window.addEventListener('resize', updateVisibility)
|
||||
|
||||
return () => {
|
||||
document.documentElement.dataset.productStickyVisible = 'false'
|
||||
window.dispatchEvent(new CustomEvent('product-sticky-change', { detail: false }))
|
||||
window.removeEventListener('scroll', updateVisibility)
|
||||
window.removeEventListener('resize', updateVisibility)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user