Skip to content

Instantly share code, notes, and snippets.

@alexd73
Last active October 29, 2019 16:54
Show Gist options
  • Save alexd73/26d89bf366c1d282cd42f87999ab12d0 to your computer and use it in GitHub Desktop.
Save alexd73/26d89bf366c1d282cd42f87999ab12d0 to your computer and use it in GitHub Desktop.
Компонент для промотки чисел от и до (`npm install --save vue-observe-visibility и gsap`)
<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