|
@@ -1350,6 +1350,19 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 是否el的一部分在可视区域
|
|
|
+ function isInViewport (el) {
|
|
|
+ if (!el) return
|
|
|
+ var offset = el.getBoundingClientRect()
|
|
|
+ var x = 64 // 头部偏移
|
|
|
+ var offsetTop = offset.top + x
|
|
|
+ var offsetBottom = offset.bottom
|
|
|
+
|
|
|
+ // 是否在可视区域
|
|
|
+ var inViewport = offsetTop <= window.innerHeight && offsetBottom >= x
|
|
|
+ return inViewport
|
|
|
+ }
|
|
|
+
|
|
|
// 必须在$(function () {})中调用
|
|
|
function windowScrollFn () {
|
|
|
// refreshStickyInfo()
|
|
@@ -1357,33 +1370,27 @@
|
|
|
// 判断xx是否处于可视区域
|
|
|
var mainFooter = $('.info.main_footer')
|
|
|
var stickyFooter = $('.sticky-footer')
|
|
|
- var offset = mainFooter[0] && mainFooter[0].getBoundingClientRect()
|
|
|
- var offsetTop = offset.top + 64
|
|
|
- var offsetBottom = offset.bottom
|
|
|
- var offsetHeight = offset.height
|
|
|
- // 是否在可视区域
|
|
|
- // window.innerHeight 视口高度
|
|
|
- var inViewport = offsetTop <= window.innerHeight && offsetBottom >= 0
|
|
|
- if (inViewport) {
|
|
|
- // 在可视区域
|
|
|
- // console.log('in')
|
|
|
- stickyFooter.hide()
|
|
|
- } else {
|
|
|
- // 不在可视区域
|
|
|
- // console.log('out')
|
|
|
- stickyFooter.show()
|
|
|
|
|
|
+ var show = !isInViewport(mainFooter[0])
|
|
|
+
|
|
|
+ if (show) {
|
|
|
+ stickyFooter.show()
|
|
|
// 吸底
|
|
|
// 如果距离底部
|
|
|
var bottomFooter = $('.j-bottom')
|
|
|
- var ob = bottomFooter[0] && bottomFooter[0].getBoundingClientRect()
|
|
|
+ var ob = { top: 0 }
|
|
|
+ if (bottomFooter.length) {
|
|
|
+ ob = bottomFooter[0] && bottomFooter[0].getBoundingClientRect()
|
|
|
+ }
|
|
|
// bottom出现在视口
|
|
|
var bottom = window.innerHeight - ob.top
|
|
|
- if (bottom > 0) {
|
|
|
- stickyFooter.css({ bottom: bottom })
|
|
|
+ if (bottom > 0 && ob.top !== 0) {
|
|
|
+ stickyFooter.css({ bottom: parseInt(bottom) })
|
|
|
} else {
|
|
|
stickyFooter.css({ bottom: 0 })
|
|
|
}
|
|
|
+ } else {
|
|
|
+ stickyFooter.hide()
|
|
|
}
|
|
|
}
|
|
|
$(window).on('scroll', windowScrollFn)
|