<template>
<div>
<div class =
"fixed"
v-
if
=
"!showAbsoluteBack"
:style =
"styleOpacity"
>
<div class =
"fixedBack"
@click =
"goBack"
>
<i class =
"iconfont"
>&
#xe677;</i>
</div>
<div class =
"title"
>故宫</div>
</div>
<div class =
"absoluteBack"
@click =
"goBack"
v-
if
=
"showAbsoluteBack"
><i class =
"iconfont"
>&
#xe677;</i></div>
</div>
</template>
<script>
export
default
{
name:
'detailHeader'
,
data (){
return
{
showAbsoluteBack:
true
,
styleOpacity: {
opacity: 0
}
}
},
methods: {
goBack () {
this
.$router.back()
},
handleScroll (){
const top = document.documentElement.scrollTop;
if
(top > 0){
let opacity = top / 135
opacity = opacity > 1 ? 1 : opacity
this
.styleOpacity = {
opacity
}
this
.showAbsoluteBack =
false
}
else
{
this
.showAbsoluteBack =
true
}
}
},
activated (){
window.addEventListener(
'scroll'
,
this
.handleScroll)
},
deactivated (){
window.removeEventListener(
'scroll'
,
this
.handleScroll)
}
}
</script>
<style lang=
"stylus"
scoped>
@import
'~styles/varibles.styl'
.absoluteBack
position absolute
width 20px
line-height 20px
top 20px
left 20px
padding 10px
border-radius 50%
background-color rgba(0,0,0,.7)
color white
text-align center
font-size 20px
z-index 2
.fixed
width 100%
position fixed
height $headerHeight
z-index 5
background-color $bgColor
.fixedBack
position absolute
padding 13px
float left
color white
.title
font-size 20px
color white
line-height $headerHeight
text-align center
.iconfont
font-size 24px
</style>