How to Create Image Transition in JavaScript

In this article, we would be implementing a simple and user friendly image transition using JavaScript. To view the demo, click HERE.

Why Transitions

Transitions are animations used to keep users oriented during user interface (UI) state changes and object manipulations, and make those changes feel smooth instead of jarring. Good transitions feel natural, often giving the illusion that users are interacting with real-world objects.

Requirements

Think of GSAP as the Swiss Army Knife of animation…but better. It animates anything JavaScript can touch (CSS properties, canvas library objects, SVG, generic objects, whatever) and it solves lots of browser inconsistencies, all with blazing speed (up to 20x faster than jQuery).

You can find the CDN for the GSAP here.

Three.js is JavaScript 3D library.  You can find the CDN for the Three.js here.

This is JavaScript library to draw and animate images on hover. We will make use of the library to quickly put together the animations.

I often make use of Pexels for image inspirations, it has thousands of image and feel free to select amazing images from different categories.

Now let’s get to code, Yeah!

First, I need to give a walkthrough of how I structured my folders for the project.

 

Index.html

This helper needs Three.js and TweenMax to do the transition, so you need to include it before this little helper. Then you only need a div element in HTML to start animating things with a piece of code like this.

app.js

Configures and adds the images and displacement image in the hoverEffect object, intensity defines how we want the animation to take be effectives (ease in and ease out). Feel free to play around with the values.

style.css

It helps to style and position the contents on the page.

Next, download hover.umd.js.

Finally we are done with implementing image transitions using JavaScript libraries.

Click HERE to download the project source code.

CategoriesTags

Related Posts