0

I am trying to re-write this code in javascript only without the jquery part.

var imgs = $.makeArray($("#images img"));
imgs.reverse();

function crossfade() {
  TweenMax.to(imgs[0], 1, { autoAlpha: 0, scale: 1 });
  TweenMax.to(imgs[1], 1, { autoAlpha: 1, scale: 1.2 });
  imgs.push(imgs.shift());
}

var cycle = setInterval(crossfade, 3000);

Most especially the below part.

var imgs = $.makeArray($("#images img"));
imgs.reverse();
Raghul SK
  • 1,256
  • 5
  • 22
  • 30
dotun seyi
  • 43
  • 1
  • 10
  • 2
    Read [this answer](https://stackoverflow.com/a/2735133/10210841). I found this question with just a few minutes of research. Next time, try rewording your question while doing your own searching. – Rojo Jul 19 '20 at 13:54
  • 1
    Does this answer your question? [How to convert a DOM node list to an array in Javascript?](https://stackoverflow.com/questions/2735067/how-to-convert-a-dom-node-list-to-an-array-in-javascript) – Ivar Jul 19 '20 at 13:57
  • You should upgrade to [GSAP 3](http://greensock.com/3). – Zach Saucier Jul 20 '20 at 12:15

2 Answers2

0

Get the Images with document.querySelectorAll, then put them in an array (as @rojo said in his comment) and reverse the order of that array.

var images = document.querySelectorAll("#images img"), //get the images as nodelist
    images = Array.from(images), //transform the nodelist to an array
    images = images.reverse() //reverse the array

// proceed with images...


korki
  • 163
  • 7
-1

This might help you

Array.from(document.querySelectorAll('#images img')).reverse()

Beingnin
  • 2,288
  • 1
  • 21
  • 37