Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

spelling mistake #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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