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 MySQL Community Server 5.6.39

This article records the detailed tutorial of MyS...

jQuery plugin to implement search history

A jQuery plugin every day - to make search histor...

Detailed explanation of the solution to font blur when using transform in CSS3

This question is very strange, so I will go strai...

Vue Basics Listener Detailed Explanation

Table of contents What is a listener in vue Usage...

Practical record of Vue3 combined with TypeScript project development

Table of contents Overview 1. Compositon API 1. W...

Solution to mysql server 5.5 connection failure

The solution to the problem that mysql cannot be ...

How to manually upgrade the node version under CentOs

1. Find the corresponding nodejs package, refer t...

React method of displaying data in pages

Table of contents Parent component listBox List c...

Mini Program natively implements left-slide drawer menu

Table of contents WXS Response Event Plan A Page ...

How to solve the mysql insert garbled problem

Problem description: When inserting Chinese chara...

What is the function and writing order of the a tag pseudo class

The role of the a tag pseudo-class: ":link&qu...

Page Refactoring Skills - Javascript, CSS

About JS, CSS CSS: Stylesheet at the top Avoid CS...

Mysql SQL statement operation to add or modify primary key

Add table fields alter table table1 add transacto...

How to build YUM in Centos7 environment

1. Enter the configuration file of the yum source...