简体   繁体   中英

Making a div disappers on scroll

I am using the following method to hide a div on scroll.

My div:

<div v-if="this.scrollPosition < 20" class="container mt-3 serious">
        <h2>This is a big title</h2>            
</div>

The method I use:

 const app = new Vue({    
      el: '#app',    
      data: {
        scrollPosition: null
      },    
      methods: {
        updateScroll() {
          this.scrollPosition = window.scrollY
        }
      },    
      mounted() {
        window.addEventListener('scroll', this.updateScroll);
      }    
    })

My problem is that if I scroll slowly, the div disappears and then reappears, how can I fix this?

Have you tried changing v-if="this.scrollPosition < 20" to maybe another value like 15?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM