MediumLightbox.JS – Elegant Image Zoom

MediumLightbox plugin is inspired by and reproduces exactly the same code to add this smooth transition over the image. Though, there is some improvement. The plugin is written in pure JavaScript which gives better performance and it is very lightweight.

It works on mobile devices (which fails to do) and it is very simple, just like Fluidbox.


Here is how to use MediumLightbox.JS

Step 1

Include the plugin itself as well as the stylesheet. The styles included are only for demo purposes, so you can change it and remove the styles you do not need.

<link href="style.css" rel="stylesheet">
<script src="mediumLightbox.js" ></script>

Step 2


<figure class="half left zoom-effect">
    <div class="aspectRatioPlaceholder" >
        <div class="aspect-ratio-fill" style="padding-bottom: 50%;"></div>
        <img class="img" data-width="900" data-height="450" src="image.jpg">

To do some calculations some attributes are necessary:

  • data-width: the real width of the image.
  • data-height: the real height of the image.
  • To the div with aspect-ratio-fill class is applied a padding-bottom that is the aspect ratio of the image. The aspect ratio percentage is found with [(height/width)*100] formula.

Step 3

Initialize the lightbox plugin:


There is an option for the margin which is applied to the imaged in its zoomed view. By default, it is 20px but it can be adjusted by adjusting the code as below:

MediumLightbox('figure.zoom-effect', {


Don’t struggle alone with projects

Join the creative community of UX, graphic, web designers and developers to get help with any design or dev project.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *