Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ export default {
elStyle.zIndex = zIndex
} else {
elStyle.position = ''
childStyle.cssText = `left: 0; right: 0; top: ${stickyTop}px; z-index: ${zIndex}; ${childStyle.cssText}`
childStyle.top = `${stickyTop}px`
childStyle.zIndex = zIndex
}

let active = false

const sticky = () => {
const sticky = (left, right) => {
if (supportCSSSticky || active) return
if (!elStyle.height) {
elStyle.height = `${el.offsetHeight}px`
}
if (childStyle) {
childStyle.position = 'fixed'
childStyle.left = `${left}px`
childStyle.right = `${right}px`
}
active = true
}
Expand All @@ -73,8 +76,12 @@ export default {

listenAction = throttle(() => {
const offsetTop = el.getBoundingClientRect().top
const offsetLeft = el.getBoundingClientRect().left
const windowWidth = document.documentElement.clientWidth
const offsetRight = el.getBoundingClientRect().right
console.log(el.getBoundingClientRect())
if (offsetTop <= stickyTop) {
return sticky()
return sticky(offsetLeft, windowWidth-offsetRight)
}
reset()
})
Expand Down