hotspot: setHeight + callbackFN
This commit is contained in:
@@ -294,3 +294,28 @@ function idmObserveOnce(element, callback, options = { root: null, rootMargin:
|
||||
|
||||
observer.observe(element);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// IDM SET HEIGHT
|
||||
app_shop.fn.idmSetHeight = options => {
|
||||
const { selector, selectors, container } = options || {}
|
||||
if ((!selector && !selectors) || !container) return
|
||||
|
||||
const containerElement = document.querySelector(container)
|
||||
if (!containerElement) return
|
||||
|
||||
const adjustAllHeights = itemSelector => {
|
||||
const targets = containerElement.querySelectorAll(itemSelector)
|
||||
if (!targets.length) return
|
||||
|
||||
targets.forEach(el => (el.style.minHeight = ''))
|
||||
|
||||
const max = Math.max(...[...targets].map(el => el.offsetHeight || 0))
|
||||
|
||||
targets.forEach(el => (el.style.minHeight = `${max}px`))
|
||||
}
|
||||
|
||||
if (selector) adjustAllHeights(selector)
|
||||
if (selectors?.length) selectors.forEach(adjustAllHeights)
|
||||
}
|
||||
Reference in New Issue
Block a user