WebGL Distortion Hover Effects
Publikováno: 10.4.2018
A little library that can be used for creating WebGL powered distortion hover effects using displacement images.
WebGL Distortion Hover Effects was written by Robin Delaporte and published on Codrops.
Today we’d like to share a little hover effect library with you. The effect goes as follows: when hovering an image, we’ll use a displacement image to transition to another image. Using different displacement images, we can create a variety of looks. The main idea behind this little library is to recreate an effect similar to what we have done previously, but with broader support, better performance and that is easier to customize.
The demo is kindly sponsored by HelloSign API: Everything IT requires and Developers love. If you would like to sponsor one of our demos, find out more here.
The animation is based on WebGL and we use three.js, so it works in all recent browsers.
To get started we need two main images and one displacement image to create the effect.
Here is an example displacement image we’re using:
The effect works in the following three steps:
- Modifying the images with the displacement image
- A classic fade between the 2 images
- Reverse the displacement
We can use a simple div to initiate our effect:
var myAnimation = new hoverEffect({
parent: document.querySelector('.my-div'),
image1: 'images/myImage1.jpg',
image2: 'images/myImage2.jpg',
displacementImage: 'images/myDistortionImage.png'
});
Keep in mind that the demo needs to run in a server environment.
We hope you like this library and find it useful!
References and Credits
- Three.js
- TweenMax.js by GreenSock
- Photography by Unsplash
- Patterns designed by Freepik.com
- ImagesLoaded by Dave DeSandro
WebGL Distortion Hover Effects was written by Robin Delaporte and published on Codrops.