Home > Article > Web Front-end > HTML5 practice-setting images to grayscale_html5 tutorial skills
In the past, to display grayscale images on the web, you had to manually convert them using image software. But now this process can be achieved with the help of HTML5 canvas, without the need to use image editing software. I made a demo using html5 and jquery to show how to implement this function.
Purpose
This demo will show you how to use HTML5 and jquery to switch between the grayscale image and the original image when the mouse moves out of the image. Before the emergence of HTML5, to implement this function, you needed to prepare two images, one grayscale image and one original image. But now it can be achieved faster and easier with the help of HTML5, because the grayscale image is generated directly on the original image. I hope this js code will be helpful when you create a file or image display function.
Rendering
jquery code
The following jquery code will find the target image and generate a grayscale Version. When you move your mouse over the image, the grayscale image changes to primary color.