Complete code for implementing the vue backtop component

Complete code for implementing the vue backtop component

Effect:

insert image description here

Code:

<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, //Initialize hidden components 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
    //Screen height 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>

This is the end of this article about the complete code implementation of the vue backtop component. For more related vue backtop component content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How does Vue pass Slot implementation across components
  • vue-calendar-component encapsulates the example code of the multi-date selection component
  • How to implement Vue's tree component
  • Causes and solutions for failure of throttling function in Vue components
  • Set ref operation for subcomponents through render function in Vue
  • Antd-vue Table component adds Click event to click on a row of data tutorial
  • Summary of several ways to create and call Vue components in HTML

<<:  Mysql Sql statement comments

>>:  Detailed explanation of redis persistence, master-slave synchronization and sentinel under Linux

Recommend

How to install and configure MySQL and change the root password

1. Installation apt-get install mysql-server requ...

Detailed explanation of Linux netstat command

Table of contents Linux netstat command 1. Detail...

Introduction to html form control disabled attributes readonly VS disabled

There are two ways to disable form submission in ...

How to deal with garbled characters in Mysql database

In MySQL, database garbled characters can general...

IE6/7 is going to be a mess: empty text node height issue

Preface: Use debugbar to view document code in iet...

MySQL stored functions detailed introduction

Table of contents 1. Create a stored function 2. ...

JavaScript canvas to achieve raindrop effects

This article example shares the specific code of ...

Sharing of experience on repairing MySQL innodb exceptions

A set of MySQL libraries for testing. The previou...

Summary of MySql index, lock, and transaction knowledge points

This article summarizes the knowledge points of M...

Detailed explanation of the basic use of react-navigation6.x routing library

Table of contents react-native project initializa...

Use JS to operate files (FileReader reads --node's fs)

Table of contents JS reads file FileReader docume...

How to get USB scanner data using js

This article shares the specific process of js ob...

MySql grouping and randomly getting one piece of data from each group

Idea: Just sort randomly first and then group. 1....