Home > Article > Web Front-end > How to implement the scroll event in vue with animation effects
Requirements: When we want to pull down the page, and then some messages pop up at the top, how to implement it, first think of using the scroll event of the page, and then think of where to write the event. Not much to say, look at the code
<template> <p class="home"> <p id="zz"> <transition name="bounce"> <ap v-show="aa"></ap> </transition> <app></app> <!--<lunBo></lunBo>--> <lunbotu id="lunbotu"></lunbotu> 。。。。 </p> </p></template>
What will appear at the top of the above code is the content in the ap component. Here v-show is used to determine whether to display it. The external transition uses animation effects to slow down the module. What needs to be noted here is that the name attribute is used in the transition, not the class attribute
<script> import ap from './app.vue' import app from './header-app.vue' import lunBo from './lunbo.vue' ...... export default{ data () { return { scroll: '', aa: false } }, components: { ap, app, ...... }, mounted () { window.addEventListener('scroll', this.menu) }, methods: { menu () { this.scroll = document.body.scrollTop if (this.scroll >= 115) { this.aa = true } else { this.aa = false } } } } </script>
The code here is to handle the page scroll event. Let’s take a look at how to handle the animation event
<style> .bounce-enter-active { animation: bounce-in .5s; } .bounce-leave-active { animation: bounce-out .5s; } @keyframes bounce-in { 0% { transform: translateY(-85px); } /*50% {*/ /*transform: translateY(-45px);*/ /*}*/ 100% { transform: translateY(0); } } @keyframes bounce-out { 0% { transform: translateY(0); } /*50% {*/ /*transform: translateY(-45px);*/ /*}*/ 100% { transform: translateY(-85px); } }</style>
The above code handles animation events. Custom events are used here
The above is the detailed content of How to implement the scroll event in vue with animation effects. For more information, please follow other related articles on the PHP Chinese website!