link411 link412 link413 link414 link415 link416 link417 link418 link419 link420 link421 link422 link423 link424 link425 link426 link427 link428 link429 link430 link431 link432 link433 link434 link435 link436 link437 link438 link439 link440 link441 link442 link443 link444 link445 link446 link447 link448 link449 link450 link451 link452 link453 link454 link455 link456 link457 link458 link459 link460 link461 link462 link463 link464 link465 link466 link467 link468 link469 link470 link471 link472 link473 link474 link475 link476 link477 link478 link479 link480 link481 link482 link483 link484 link485 link486 link487 link488 link489 link490 link491 link492 link493 link494 link495 link496 link497 link498 link499 link500 link501 link502 link503 link504 link505 link506 link507 link508 link509 link510 link511 link512 link513 link514 link515 link516 link517 link518 link519 link520 link521 link522 link523 link524 link525 link526 link527 link528 link529 link530 link531 link532 link533 link534 link535 link536 link537 link538 link539 link540 link541 link542 link543 link544 link545 link546 link547

[Vue.js] animation of picture doesn't work! Vue.js

The problem is when when using set interval with this top: ${this.imgTop++}px!

const vue.js = require(“@/assets/images/vue.png”);
const bootstrap = require(“@/assets/images/bootstrap.png”);
const bulma = require(“@/assets/images/bulma.png”);

export default {
name: “randImg”,
data() {
return {
images: [
addedImage: [],
imgTop: -100,
imgLeft: -100,
imgHeight: 64,
imgWidth: 64,
changeInterval: 750,
selectedImage: ‘’
created() {
const randomImg = func => setInterval(func, this.changeInterval);
methods: {
randomImage() {
const idx = Math.floor(Math.random() * this.images.length);
this.selectedImage = this.images[idx];
randomPosition() {
const randomPos = twoSizes => Math.round(Math.random() * twoSizes);
this.imgTop = randomPos(window.innerHeight - this.imgHeight);
this.imgLeft = randomPos(window.innerWidth - this.imgWidth);
moveRandomImage() {
const randomImg = func => setInterval(func, this.changeInterval);
addImage() {
style: {
top: `${this.imgTop}px`,
left: `${this.imgLeft}px`,
height: `${this.imgHeight}px`,
width: `${this.imgWidth}px`
src: this.selectedImage
moveImage() { = {
style: {
top: `${this.imgTop++}px`

don’t understand why but this animataion doesnt work,
basically i will explain how it works:
every second when adding new image with new position from addedImage: [] and this every picture to go down (top++)

additionally this is a template:

<div class=”randImg”>
<img class=”image” :style=””
v-for=”image in addedImage”>

Solution :

My guess it’s possible to achieve what you want by adding a watcher on the addedImage array, like every time a new image element is added, you change the of it.

But you shouldn’t use nested setIntervals. I share you this answer explaining why.

I think a simpler and lighter solution is to use css, like creating a @keyframe translation rule:

.drop {
animation: dropDown 1.5s ease-in forwards;

@for $i from 1 to 10 {
.drop:nth-child(#{$i}) {
animation-delay: $i * 1.5s;
animation-duration: -1.5s;

@keyframes dropDown {
0% {
transform: translateY(0);
100% {
transform: translateY(600px);
opacity: 0;

Here’s a live example

Solution 2:

this.addedImage is an array of image, not an image. So, when you do, you add a style attribute to the array, but not to the images in the array.

Change moveImage for :

moveImage() {
this.addedImage.forEach(image => { = + 1