Enlarge Image on Hover

Add a desktop and mobile-friendly magnifier for images on mouse hover using custom code.

You may have images in your website that are rich in intricate details — such as product photos or artwork. By using some custom code, you can enable your visitors to hover over and amplify specific parts of these images — all without having to move a muscle. 

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.

This tutorial will guide you through the process of enlarging your images by inserting custom code into a page or a project by following these steps: 

  1. Insert the custom code
  2. Assign a class name
  3. Customize 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>
    

Insert the custom code

There are two methods to insert the custom code into your project: 

  • Include the code in the entire project
  • Integrate the code in an individual page

To insert the code into your entire project:

  1. Access your project’s Settings
  2. Select the Custom code tab
  3. Insert the code into the Footer code section (e.g., “Before </body> tag”)
  4. Click Save changes

Note: You can insert the code into your project using hotkeys 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. 
The image magnification custom code should be placed in the Footer code section of the project’s settings, and Before the </body> tag.

To insert the code into an individual page: 

  1. Launch the Designer
  2. Access the Pages panel and select the page settings cog icon of the desired page
  3. Scroll to the Custom code section within the page settings
  4. Insert the code into the Before </body> tag section
  5. Click Save

Note: You can paste the code into your project using hotkeys 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. 
A page’s custom code settings are highlighted, specifically the Before </body> tag section.

You have successfully integrated the custom code into your project!

Assign a class name

Let’s assign a unique class name to the images that we want to apply the magnification effect to:

  1. Select the Image you wish to magnify
  2. Access the Style panel and click on the Selector field
  3. Give it a class (e.g., “Magnify”) 
The selector field of an image shows a new class of “Magnify” added to it.

Let’s include the “Magnify” class in our code: 

  1. Access the Pages panel and select the page settings cog icon of the page where your custom magnifier code is placed
  2. Scroll to the Before </body> tag section in your page’s settings
  3. Replace “.image” with your class name (e.g., “.magnify”) 
  4. Click Save
After inserting the code for image enlargement into the custom code of the page settings, ensure to modify the code to correspond to the newly defined “Magnify” class.

Helpful tip: Instead of replicating or copying classes in an ongoing project, consider using a Global class or a Combo class to establish a unique class for images intended for magnification. Ensure that the distinct magnification class name has been included in your custom code according to the previously outlined steps. Discover more about Global classes and Combo classes.

Go ahead and publish your project and navigate to your live site to witness your personalized code in operation. Simply hover over the image where you’ve applied the class name (such as images identified with the class name “Magnify”), and observe a magnifying glass tracking your cursor movements as you glide it across the image.

Customize the magnifying tool

By default, the magnifying glass is a square measuring 150 by 150 pixels. Let’s modify its dimensions, shape, and introduce a drop shadow effect.

The default setting in our custom code specifies the magnifier size as 150 by 150 pixels. Let’s enlarge it:

  1. Access the Pages panel and select the page settings cog icon on the page containing your tailored magnifying code.
  2. Scroll down to the Before </body> tag section within your page settings and pinpoint the “magnifiersize: [150, 150]” snippet of code.
  3. Adjust both 150 pixel values to a larger figure (e.g., 300 pixels for each).
  4. Save your changes.
To adjust the size of the magnifier, you must modify the pixel values in the magnifier size section of the custom code within the page’s settings.

Let’s transform the magnifier shape from a square to a circle by setting a foundational style on a fresh Div block:

  1. Open the Navigator and choose the Body element.
  2. Utilize Quick find to insert a Div block as the concluding element on the page.
  3. Select the Div block, launch the Style panel, and click into the Selector field.
  4. Assign a class name to the Div block to enable the custom code to recognize the new magnifier shape (e.g., “round-loope”).
  5. Access Style panel > Borders and define a Radius of 50%.

At this stage, the Div block might appear oval, but the magnifier’s size is controlled by the 300 pixels you previously set.

Insider tip: Press Command + E (on Mac) or Control + E (on Windows) to trigger Quick find and promptly append elements to your project.

The Selector field of the styled Div block displays a novel class of “round-loope” appended to it.
The Border radius of the “round-loope” Div block is adjusted to 50%.

To introduce more depth to the magnifier, let’s include a shadow behind it:

  1. Choose the Div block.
  2. Access the Style panel > Effects.
  3. Incorporate a Box shadow by selecting the plus icon and customize the shadow according to your preference.

Since our “round-loope” Div block solely affects the styling of our magnifier, we do not want the Div block to be visible on our page. Let’s conceal it from view:

  1. Select the “round-loope” Div block.
  2. Open the Style panel > Layout.
  3. Adjust the Display to none.
  4. Publish the project and explore your site to preview the newly styled magnifier.
An image showcasing pink, red, and green boxes and watches magnified upon hovering using custom code integrated into the page’s custom code settings within the Webflow Designer.

The magnifying tool also functions on mobile gadgets. Users can tap on the image to view close-ups, especially on devices like tablets and smartphones.

An image presenting pink, red, and green boxes and watches magnified on mobile devices by tapping on segmented areas of the image. This capability is achieved through custom code integrated into the page’s custom code settings in the Webflow Designer.

Congratulations! You’ve enhanced the potential of your images with magnification capabilities!

Ewan Mak
Latest posts by Ewan Mak (see all)