Suppose this is my template:
<template>
<div id="Test">
<transition name="fade">
<div class="row" id="RowOne">
<p>Lorem ipsum dolor odit qui sit?</p>
</div>
</transition>
<transition name="fade">
<div class="row" id="RowTwo">
<p>Lorem ipsum dolor sit amet, consectetur.</p>
</div>
</transition>
<transition name="fade">
<div class="row" id="RowThree">
<p>Lorem ipsum dolor sit amet, tenetur!</p>
</div>
</transition>
</div>
</template>
I want to display and animate RowOne, RowTwo and RowThree
when it's in the displayed in the viewport, respectively. Like in the Laracasts website, the elements appear and animate when scroll position reaches the elements offset. Is it possible using Vue.js and javascript?
Here is how you can do it with a
directive
.You will need to add
v-vpshow
directive to the elements you want to animate when they become visible in the viewport.For example:
This directive uses two classes.
1)
before-enter
: it hides the element by default and is added automatically when the directive is bound to the element.2)
enter
: this one should contain the transition you want to apply when the element becomes visible.v-vpshow
will unbind itself automatically once the element has become visible (after triggering the animation) in the viewport removing any data and events listeners that were set onbind
.Here is a working example.
Yeah it should be. You should just have to set the
display
property fromnone
to something visible when you detect that the user has scrolled a certain distance.Here's another question with answers that will help you implement that: Show div on scrollDown after 800px