From our sponsor: Leverage AI for dynamic, custom website builds with ease.
Today we want to share a neat image blur effect with you. Using canvas, we want to blur images on the transition to another one, creating a smooth effect.
We will be using Stack Blur, which is a fast, almost Gaussian blur for Canvas by Mario Klingemann from Quasimondo.
The images used in the demo are by Geoff Peters. They are licensed under the Attribution 2.0 Generic (CC BY 2.0) License.
How it works
The main idea is to add some images in our structure that will serve as background images. We will add the canvas element which will contain a blurred version of the image. When we navigate, we’ll add the blurred canvas behind the current image and fade the current image out. With the blurred canvas image now visible, we can either show the new image immediately (unblurred) or show it blurred and then “sharpen” it.
You can set that by changing the variation between 1 and 2:
animOptions = { speed : 700, variation : 1, blurFactor : 10 }
The speed is the animation speed between each transition (from normal to blurred) and the blurFactor is basically the radius for the blur effect used in Stack Blur.
Demos
- Demo 1: Here we use variation 2, showing the coming image without blurring it first.
- Demo 2: In this demo we use variation 1 for blurring both, the current image and the coming one.
We hope you liked our little experiment and find it inspiring and useful!