< div : class = "IconShow ? 'mhomeIcon' : 'IconOff'" >
< img src= "@/assets/news.svg" alt= "" >
< / div>
const top = ref ( 0 )
const IconShow = ref ( true )
function handleScroll ( ) {
window. addEventListener ( 'scroll' , ( ) => {
top. value = document. documentElement. scrollTop || window. pageYOffset || document. body. scrollTop;
} ) ;
}
watch (
( ) => top. value,
( newValue, oldValue ) => {
if ( newValue > 0 ) {
if ( newValue > oldValue) {
IconShow. value = false
} else if ( newValue < oldValue && ( oldValue- newValue > 5 ) ) {
IconShow. value = true
}
}
} ,
{ immediate : true }
)
onMounted ( ( ) => {
handleScroll ( ) ;
} ) ;
. mhomeIcon {
position : fixed;
transition : all 1s ease- in - out 0s;
opacity : 1 ;
top : 85 % ;
right : 0 . 8rem;
width : 2rem;
height : 2rem;
background : rgba ( 255 , 255 , 255 , 0.8 ) ;
border- radius: 1rem;
cursor : pointer;
box- shadow: 0px 4px 10px 0px rgba ( 148 , 173 , 177 , 0.28 ) ;
z- index: 100 ;
transform- style: preserve- 3d;
& > img {
display : block;
margin : 0 auto;
z- index: 200 ;
width : 1 . 2rem;
height : 1 . 4rem;
margin- top: 0 . 4rem;
}
}
. mhomeIcon: after {
content : '' ;
width : 2 . 6rem;
height : 2 . 6rem;
position : absolute;
top : - 0 . 3rem;
left : - 0 . 3rem;
border- radius: 50 % ;
animation : breath . 6s linear . 5s infinite alternate;
background- color: rgba ( 43 , 204 , 204 , 0.5 ) ;
z- index: - 100 ;
transform : translateZ ( - 10px) ;
}
@keyframes breath {
0 % { opacity : 0.5 ; }
100 % { opacity : 0 ; }
}
. IconOff {
position : fixed;
right : 0 . 8rem;
bottom : 0 ;
transition : all 1s ease- in - out 0s;
top : 100 % ;
opacity : 0 ;
width : 2rem;
height : 2rem;
background : rgba ( 255 , 255 , 255 , 0.8 ) ;
border- radius: 1rem;
& > img {
display : block;
margin : 0 auto;
width : 1 . 2rem;
height : 1 . 4rem;
margin- top: 0 . 4rem; }
}