@click="$router.go(-1)">返回

export default {

name: 'Affix',

props: {

},

data () {

return {

}

},

mounted () {

window.addEventListener('scroll', this.handleScroll)

},

methods: {

handleScroll (e) {

if (document.documentElement.scrollHeight - document.documentElement.scrollTop <= document.documentElement.clientHeight + 317) {

let fxDom = document.getElementsByClassName('back-btn-position-fx-style')

if (fxDom.length > 0) {

fxDom[0].classList.add('back-btn-position-ab-style')

fxDom[0].classList.remove('back-btn-position-fx-style')

}

} else {

let adDom = document.getElementsByClassName('back-btn-position-ab-style')

if (adDom.length > 0) {

adDom[0].classList.add('back-btn-position-fx-style')

adDom[0].classList.remove('back-btn-position-ab-style')

}

}

}

}

}

.back-btn-position-ab-style {

position: absolute;

bottom: 20px;

margin-left: 1074px;

}

.back-btn-position-fx-style {

position: fixed;

bottom: 20px;

margin-left: 1074px;

}

封装时我写的这个项目底部高度是317像素,可根据自己业务需求把代码中的317改成相应的底部高度

Logo

欢迎加入 MCP 技术社区!与志同道合者携手前行,一同解锁 MCP 技术的无限可能!

更多推荐