Image magnification on hover
Add a desktop and mobile-friendly magnifier for images on mouse hover using custom code.
You might have images in your site that are filled with intricate details — for instance, product photos or artwork. With a little custom code, you can give your visitors the power to hover over and magnify portions of these images — and they won’t even have to lift a finger to do it.
![An image of pink, red and green boxes and watches is magnified on hover using custom code placed into a page’s custom code settings in the Webflow Designer.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8d9e2f_6050061d8d70cf39c39aeb65_uLfds7S9YMOKReOVt7Zc9guW4IH4UL_ftPhmzu2FLuvsyrn45S7z_5IG8qr85Ax4jn_IetMAoFEAwhEcUKx2kZbWTR2hXnPF0iElxlyTMFntzuQ5VX8DhfI65Vg1Z3zbobapER7D.png)
In this lesson you’ll learn how to magnify your images by adding custom code to a page or a project doing the following:
- Paste the custom code
- Add a class name
- Style the magnifier
<script type="text/javascript" src="https://assets.website-files.com/5e2755779d8b8ea1d6373797/5ea88e92dce9b4b66f165490_zoom.txt"></script>
<script>
jQuery(function(){
if(!$.fn.imagezoomsl){
$('.msg').show();
return;
}
else $('.msg').hide();
// plugin initialization
$('.image').imagezoomsl({
innerzoommagnifier: true,
classmagnifier: "round-loope",
magnifiersize: [150, 150],
// disables the scrolling of the document with the mouse wheel when the cursor is over the image
disablewheel: false
});
});
</script>
Paste the custom code
There are two ways you can paste the custom code into your project:
- Add the code to the entire project
- Add the code to an individual page
To paste the code into your entire project:
- Go to your project’s Settings
- Choose the Custom code tab
- Paste the code into the Footer code section (e.g., “Before </body> tag”)
- Click Save changes
Note: You can paste the code into your project using shortcut keys Command + V (on Mac) or Control + V (on Windows).
![The Custom code tab is selected in a project’s settings to show where custom code across a project can be placed.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9014c07753bf8d9e08_6050061d120fca34400220a8_kpJO5KlWwjGPlKn8sTffA7ihzHxsIqQRJoBAcdgCSIwBj0XIxH44uABLZisoCEBZxkAcqWMtM31x2wy-cdKTLOACtQC_v1zk8RqHbuYkNbYibk4FF6dYVkABz0OnW51RCxM6LLZk.png)
![The image magnification custom code should be placed in the Footer code section of the project’s settings, and Before the </body> tag.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8d9e17_6050061dd2a1b587ecc74690_mpCOUi3zo9ZJ3Cjg2LRvQ-aJzTYz9wxNGyry-bBGySh585do7mnF1KBuT9heN4c-IWq5igDtFTk8b6J4TmYBlEZb3ZgZ7UbNt3yufRX-FjqnEusu3CM-MItvykctGUZOmx3E3XH-.png)
To paste the code into an individual page:
- Open the Designer
- Open the Pages panel and click the page settings cog icon of the page you want to affect
- Scroll down to the Custom code section of the page settings
- Paste the code into the Before </body> tag section
- Click Save
Note: You can paste the code into your project using shortcut keys Command + V (on Mac) or Control + V (on Windows).
![To access a page’s settings, open the Pages panel and hover over the page to see a cog icon to click.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8d9ead_605222baa8db740a4d5eb345_3d.jpeg)
![A page’s custom code settings are highlighted, specifically the Before </body> tag section.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8d9e37_6050061d2fa23067cc14a16a_oOlcIE_yvHRcY5dQTJNZ8Bhj5-ElynnkEgqyT2RrljuYV9YMySNDkvYU4EOiwNpPWkt-lNw7QDlC9YrWQWm_242kAN19avrZcbHeR0OHxfNCqWDo9SVj9e8nKz2E6uzySEQxgT8t.png)
You've successfully pasted the custom code into your project!
Add a class name
Let’s add a unique class name to the images we want to receive the magnification effect:
- Select the Image you want to magnify
- Open the Style panel and click into the Selector field
- Give it a class (e.g., “Magnify”)
![The selector field of an image shows a new class of “Magnify” added to it.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8da04c_6050061d6cd671915b57bb11__UYq_PVye6Av-N3Yx4DPux7lArCq8yY29J3iXd8Iaj96qRJujOz4b7pyUXsoNXA_e2_bXpyDSUqUcO65wOlZvIuFKIPV1WFsopJrstDbzW3Wd4lbpAhkyIszVn1OH6ey1Dst09ER.png)
Let’s add the “Magnify” class to our code:
- Open the Pages panel and click the page settings cog icon of the page containing your custom magnifier code
- Scroll to the Before </body> tag section in your page’s settings
- Replace “.image” with your class name (eg., “.magnify”)
- Click Save
![After adding the image magnification code to the page’s custom code in page settings, you need to update the code to reflect the custom “Magnify” class you have just created.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8d9e44_6050061da558dc5ddfdbd312_hxQFjgqFRrdNxcX9l4L-H38geeUisb6a5-Fk8q8M4jVFUh_EkmOjvraKXqceoBEHioKzEV9Y2oRp-OaYYfGIGuK0lem63dklV7SANwjhvG3n4JMfyWg1T4dBgpZEcog2Jkyrx82_.png)
Pro tip: Instead of recreating or duplicating classes within an existing project, you can use a Global class or a Combo class to create a unique class for images you want to magnify. Just make sure your unique magnification class name has been added to your custom code following the steps above. Read more about Global classes and Combo classes.
Publish your project and visit your live site to see your custom code in action. Hover over the image you’ve added the class name to (e.g., images with the class name “Magnify”) and you’ll see a magnifier following your mouse position as you move it over the image.
Style the magnifier
By default, the magnifier is a 150 by 150 pixel square shape. Let’s change its size and shape, and give it a drop shadow.
Out of the box, our custom code sets the magnifier size to 150 by 150 pixels. Let’s make it larger:
- Open the Pages panel and click the page settings cog icon of the page containing your custom magnifier code
- Scroll to the Before </body> tag section in your page’s settings and locate the “magnifiersize: [150, 150]” section of code
- Change each 150 pixel value to a larger value (e.g., 300 pixels for each)
- Click Save
![To change the size of the magnifier, you need to update the pixel values in the magnifier size area of the custom code within the page’s settings.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9014c07753bf8d9e10_6050061d07c237565dc40b8e_C7_L-KUNBZ5VNgSpBhQ0yTy5KDLPrJr1zwy0RLUVhmcxlrrIUFBIBGhSCM5yVSkHsUwuNIWzcI5XVAU6aefw-VxvOaqv2xPXOlVE2W_3Pb8JQWlVAf622_738ZnfGRPWzwcmrDiC.png)
Let’s change the magnifier shape from a square to a circle by setting a style foundation on a new Div block:
- Open the Navigator and select the Body element
- Use Quick find to add a Div block as the last element on the page
- Select the Div block, open the Style panel and click into the Selector field
- Give the Div block a class name so the custom code can recognize the new magnifier shape (e.g., “round-loope”)
- Open Style panel > Borders and set a Radius of 50%
The Div block may appear oval at this point, but the custom code controls the size of the magnifier — the 300 pixels you set earlier.
Pro tip: Press Command + E (on Mac) and Control + E (on Windows) to open Quick find and quickly add elements to your project.
![The selector field of the styled Div block shows a new class of “round-loope” added to it.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8da04f_6050061e1ea2614e493f7026_U8UhSUxVxT3-RZ3SpGX2ulKzTk_rWWgGHVlmi1NCtSjeLao2H0gKti5xoSgixwrIsUIixdddGR7iE4ATI71QLcotIuZ30GSC49Q9Xi37JQuyXYx2_wzUwoyTSjZk3vrgTrSONIOL.png)
![The Border radius of the “round-loope” Div block is set to 50%.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8da049_6050061e39728595ff52deab_OTVviXv3tmzuoHCCUGfrrZDeXI18DV5qOqPTfyRzegF-JbvXe5Nly4MX7O6v0RtmB-QSI4FdU9tSbNDIuI3_lwAjavRl5uADMiNM7xQyneqiGIHuJdKIKlMgmyRcbblqaAtfJD2m.png)
To give the magnifier more dimension, let’s add a drop shadow behind it:
- Select the Div block
- Open Style panel > Effects
- Add a Box shadow by clicking the plus icon, and style the shadow to your liking
Because our “round-loope” Div block is only being used to affect our magnifier’s styling, we don’t actually want the Div block to be visible on our page. Let’s hide it from view:
- Select the “round-loope” Div block
- Open Style panel > Layout
- Set Display to none
- Publish the project and visit your site to preview the newly styled magnifier
![An image of pink, red and green boxes and watches is magnified on hover using custom code placed into a page’s custom code settings in the Webflow Designer.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8d9e2f_6050061d8d70cf39c39aeb65_uLfds7S9YMOKReOVt7Zc9guW4IH4UL_ftPhmzu2FLuvsyrn45S7z_5IG8qr85Ax4jn_IetMAoFEAwhEcUKx2kZbWTR2hXnPF0iElxlyTMFntzuQ5VX8DhfI65Vg1Z3zbobapER7D.png)
The magnifier also works on mobile devices. You can tap on the image to get a closer look when using devices like tablets and smartphones.
![An image of pink, red and green boxes and watches is magnified on mobile devices when portions of the image are tapped. This is accomplished by using custom code placed into a page’s custom code settings in the Webflow Designer.](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94a9114c07753bf8da046_6050061ef205887b88d0e8dc_OGUZS8mSoYatOZvg7Nd7BhZTeKT7SO_DGrH5UcHdPwpFwybTZR_ZhOPnHwYyFUUUCQJRpsdt1OBrQJYD09Vob-z5vqlrPBZZyzuJEGjSSh_a2McZAKDcxzmPi0C_HG43Yh9dQTGb.png)
Congratulations! You’ve just magnified your images’ possibilities!