提交 8cf24e8b 编写于 作者: yma16's avatar yma16

perf:滚动条出现的逻辑修复

上级 14e35fcd
...@@ -179,7 +179,7 @@ ...@@ -179,7 +179,7 @@
border: rgba(0, 0, 0, 0); border: rgba(0, 0, 0, 0);
" "
> >
<div id="topiconid"> <div v-if="topShow">
<el-button <el-button
@click="toTop" @click="toTop"
type="info" type="info"
...@@ -281,22 +281,23 @@ export default { ...@@ -281,22 +281,23 @@ export default {
} }
}, },
watch: { watch: {
topShow: function (newvalue, oldvalue) { topShow: {
if (newvalue === true) { handler (newValue) {
document.getElementById('topiconid').style.display = 'none' if (newValue) {
} else { console.warn(newValue)
document.getElementById('topiconid').style.display = 'block' }
} },
immediate: true
} }
}, },
beforeDestroy () { beforeDestroy () {
window.removeEventListener('onload', this.topVisible()) // window.removeEventListener('onload', this.topVisible())
this.articleScrollListen('remove') this.articleScrollListen('remove')
}, },
mounted () { mounted () {
this.articleScrollListen('add') this.articleScrollListen('add')
this.initPageSpliteFun() this.initPageSpliteFun()
window.addEventListener('onload', this.topVisible()) // window.addEventListener('onload', this.topVisible())
}, },
methods: { methods: {
/** /**
...@@ -304,13 +305,14 @@ export default { ...@@ -304,13 +305,14 @@ export default {
*/ */
articleScrollListen (key) { articleScrollListen (key) {
const dom = this.$refs['mark-down-ref'] const dom = this.$refs['mark-down-ref']
const that = this
if (dom && key === 'add') { if (dom && key === 'add') {
dom.addEventListener('scroll', function (e) { dom.addEventListener('scroll', function (e) {
this.topShow = e.scrollTop > 0 that.topShow = Math.ceil(e.target.scrollTop) !== 0
}) })
} else if (dom && key === 'remove') { } else if (dom && key === 'remove') {
dom.removeEventListener('scroll', function (e) { dom.removeEventListener('scroll', function (e) {
this.topShow = e.scrollTop > 0 that.topShow = e.target.scrollTop === 0
}) })
} }
}, },
...@@ -376,9 +378,9 @@ export default { ...@@ -376,9 +378,9 @@ export default {
this.$store.commit('increment') this.$store.commit('increment')
}, },
topVisible: function () { topVisible: function () {
let dom = document.getElementById('homeTitleId') // let dom = document.getElementById('homeTitleId')
this.topShow = this.elementIsVisibleInViewport(dom) // this.topShow = this.elementIsVisibleInViewport(dom)
setTimeout(this.topVisible) // setTimeout(this.topVisible)
}, },
elementIsVisibleInViewport: function (el, partiallyVisible = false) { elementIsVisibleInViewport: function (el, partiallyVisible = false) {
try { try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册