欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue backtop組件的實(shí)現(xiàn)完整代碼

 更新時(shí)間:2021年04月07日 14:21:58   作者:五那幾諾火庫(kù)洛,火庫(kù)洛??!  
這篇文章主要介紹了vue backtop組件的實(shí)現(xiàn)完整代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

效果:

在這里插入圖片描述

代碼:

<template>
 <div class="back-top">
  <div >
   <img src="imgsrc" class="line" :class="isHide? 'isHide': 'isShow'" :style="{display: (firstShow? 'block': 'none')}" @click="backTop">
  </div>
 </div>
</template>

<script>
export default {
 name: "backTop",
 data(){
  return {
   firstShow: false,//初始化隱藏組件
   isHide: false,
   scrollFLag: true,
  }
 },
 created() {
  document.addEventListener('scroll', () => {
   let scroll = document.documentElement.scrollTop
   if(scroll > 200){
    this.isHide = false
    this.firstShow = true
   }else{
    this.isHide = true
   }
  })
 },
 methods: {
  backTop(){
   if(this.scrollFLag){
    this.scrollFLag = false
    //屏幕高度
    let scroll = document.documentElement.scrollTop
    let scrollTimer = setInterval(()=> {
     scroll -= 50
     document.documentElement.scrollTop = Math.max(scroll, 0)
     if( scroll <= 0){
      clearInterval(scrollTimer)
     }
    }, 10)
    this.scrollFLag = true
   }
  },
 },
}
</script>

<style scoped lang="scss">
.back-top{
 position: fixed;
 top: 0;
 right: 10vw;
 width: 20px;
 height: 500px;
 z-index: 200;
 .line{
  width: 12vw;
  height: 100%;
  z-index: 20;
  cursor: pointer;
  opacity: 0.8;
  transform: translateY(-100%);
  &:hover{
   opacity: 1;
  }
 }
 .isShow{
  animation: back-top-move 0.5s forwards linear, back-top-yurayura 2s 0.6s forwards linear infinite;
 }
 .isHide{
  animation: back-top-hide 0.5s forwards linear;
 }
}

@keyframes back-top-hide {
 from {
  transform: translateY(0);
 }
 to {
  transform: translateY(-100%);
 }
}

@keyframes back-top-move {
 to {
  transform: translateY(0);
 }
}
@keyframes back-top-yurayura {
 0%{transform-origin: top center;transform: rotate(0)}
 25%{transform-origin: top center;transform: rotate(2deg)}
 75%{transform-origin: top center;transform: rotate(-2deg)}
 100%{transform-origin: top center;transform: rotate(0)}
}
</style>

到此這篇關(guān)于vue backtop組件的實(shí)現(xiàn)完整代碼的文章就介紹到這了,更多相關(guān)vue backtop組件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論