Skip to content
Advertisement

converting jquery hide/fade/delay/animation to pure js

I am trying to remove the jquery dependency from my code and came across a few lines I have no idea how to replicate in js.

I know I can use setTimeout() in place of delay, css transitions for the fading, and css for the hide… just not sure how to go about it and haven’t been able to figure it out.

Any help would be appreciated.

part in question that needs converted to plain js :

JavaScript

entire original jquery code :

JavaScript

my conversion minus the section in question :

JavaScript

Advertisement

Answer

Kind of hacky, but replicates the same behavior as before which is what I wanted. I’ll look into ways to make this cleaner.

The gist is the top slider changes its image and fades in. After fade in the bottom slider changes to the same image while the top goes back to opacity 0 (keeping the same image visible). Repeats every 6 seconds going to the next image in the array.

JavaScript

css with added transition for 2s :

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement