Last active
October 29, 2019 16:54
-
-
Save alexd73/26d89bf366c1d282cd42f87999ab12d0 to your computer and use it in GitHub Desktop.
Компонент для промотки чисел от и до (`npm install --save vue-observe-visibility и gsap`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div | |
v-observe-visibility="{ | |
callback: visibilityChanged, | |
}" | |
class="digit-item" | |
>test {{digit}}</div> | |
</template> | |
<script lang="ts"> | |
import { Component, Vue, Prop, Emit } from 'nuxt-property-decorator'; | |
import { TweenLite } from 'gsap'; | |
@Component({}) | |
export default class DigitItem extends Vue { | |
@Prop({ default: 0 }) start!: number; | |
@Prop({ default: 1 }) duration!: number; | |
@Prop({ default: 0 }) end!: number; | |
tn = this.start; | |
@Emit() | |
visibilityChanged(isVisible: boolean, entry: IntersectionObserverEntry) { | |
if (isVisible) { | |
const tl = TweenLite; | |
tl.to(this.$data, this.duration, { tn: this.end }); | |
} | |
} | |
get digit() { | |
return this.tn.toFixed(0); | |
} | |
} | |
</script> | |
<style lang="scss" scoped> | |
.digit-item { | |
font-size: 100px; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment