老师问一个问题,
来源:1-5 Vue项目详情页 - 对全局事件的解绑
幻城163630
2020-08-21 21:33:41
<template>
<div>
<router-link tag="div" to="/" class='header-abs' v-show="showabs">
<div class="iconfont header-abs-back"></div>
</router-link>
<div class='header-fixed' v-show="!showabs" :style="opacityStyle">
<router-link to="/" >
<div class="header-fixed-back iconfont"></div>
</router-link>
景点详情
</div>
</div>
</template>
<script>
export default{
name:"DetailHeader",
data(){
return{
showabs:true,
opacityStyle:{opacity:0},
}
},
methods:{
handleScroll(){
// console.log(112);
const top=document.documentElement.scrollTop || document.body.scrollTop ||window.pageYOffset;
if(top>60){
let opacity=top/140;
opacity=opacity>1?1:opacity;
this.opacityStyle={opacity,};
this.showabs=false;
}else{
this.showabs=true;
}
},
},
mounted(){
window.addEventListener("scroll",this.handleScroll);
},
destroyed(){
window.removeEventListener("scroll",this.handleScroll);
},
}
</script>
<style lang="stylus" scoped>
@import '~styles/varibles.styl';
.header-abs
position:absolute;
left:.2rem;
top:.2rem;
width:.8rem;
height:.8rem;
line-height:.8rem;
text-align:center;
border-radius:.4rem;
background:rgba(0,0,0,0.8);
.header-abs-back
font-size:.4rem;
color:#fff;
.header-fixed
z-index:2;
position:fixed;
top:0;
left:0;
right:0;
overflow:hidden;
height:$headerHeight;
line-height:$headerHeight;
text-align:center;
color:#fff;
background:$bgColor;
font-size:.32rem;
.header-fixed-back
position:absolute;
top:0;
left:0;
width:.64rem;
font-size:.4rem;
text-align:center;
color:#fff;
</style>
老师我做完后发现详情页面上下移动首页也跟着上下移动这是哪儿出现问题了呢?
1回答
好帮手慕星星
2020-08-22
同学你好,将粘贴的代码放在源码中测试,并没有出现同学说的问题。detail是单独一个页面,这两个页面滚动并没有关系,建议重新启动项目测试下。
祝学习愉快!
相似问题