LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / JavaScript Codes » Zoom Image In Circle On Mouseover Using Pure JavaScript

Zoom Image In Circle On Mouseover Using Pure JavaScript

Zoom-Image-In-Circle-On-Mouseover-Using-Pure-JavaScript
Yet another lightweight image magnifier plugin that helps you to create zoom images on mouseover using JavaScript. It follows the cursor position and dynamically updates the zoomed area of the image.

This simple image zoom plugin is purely built with CSS and JavaScript without any dependency. You can use this to allow users to zoom product images on hover or use it for general-purpose image zoom functionality.

There are many code snippets available online or on many other blogs and websites, but everyone cannot optimize your blog or website, so you need some optimized code snippets. So now checkout out the code snippet for your blog and website that will give you all features for your desired code. Now grab the ready-to-use code and paste it where you want.

Features:

  1. Light Weight.
  2. Pure HTML-CSS-JSCode.
  3. Cross Browser.
  4. No JQuery Files.
  5. Fully Customizable.
  6. Responsive.

How To Create Zoom Image In Circle On Mouseover Using Pure JavaScript?

There are a few easy and understandable steps to achieve your desired functionality that we are gonna share below. Follow each step perfectly.

Recommended For You:
How To Export MySQL Database Tables To Excel XLS Using PHP?

CSS:

<style type="text/css">
#img-zoomer-box {
max-width: 500px;
height: auto;
position: relative;
margin: 10px auto;
}

#img-1 {
width: 100%;
height: auto;
}

#img-zoomer-box:hover, #img-zoomer-box:active {
cursor: zoom-in;
display: block;
}

#img-zoomer-box:hover #img-2, #img-zoomer-box:active #img-2 {
opacity: 1;
}
#img-2 {
width: 340px;
height: 340px;
background: url('https://i.pinimg.com/originals/2b/de/de/2bdede0647e3cdf75b44ea33723201d9.jpg') no-repeat #FFF;
box-shadow: 0 5px 10px -2px rgba(0,0,0,0.3);
pointer-events: none;
position: absolute;
opacity: 0;
border: 4px solid whitesmoke;
z-index: 99;
border-radius: 100%;
display: block;
transition: opacity .2s;
}
</style>

HTML:

<div id="img-zoomer-box">
<img src="https://i.pinimg.com/originals/2b/de/de/2bdede0647e3cdf75b44ea33723201d9.jpg" id="img-1" alt="Zoom Image on Mouseover"/>
<div id="img-2"></div>
</div>

JavaScript:

<script type="text/javascript">
//Demo: https://www.codehim.com/demo/zoom-image-on-mouseover-using-javascript/
let zoomer = function (){
document.querySelector('#img-zoomer-box')
.addEventListener('mousemove', function(e) {

let original = document.querySelector('#img-1'),
magnified = document.querySelector('#img-2'),
style = magnified.style,
x = e.pageX - this.offsetLeft,
y = e.pageY - this.offsetTop,
imgWidth = original.offsetWidth,
imgHeight = original.offsetHeight,
xperc = ((x/imgWidth) * 100),
yperc = ((y/imgHeight) * 100);

//lets user scroll past right edge of image
if(x > (.01 * imgWidth)) {
xperc += (.15 * xperc);
};

//lets user scroll past bottom edge of image
if(y >= (.01 * imgHeight)) {
yperc += (.15 * yperc);
};

style.backgroundPositionX = (xperc - 9) + '%';
style.backgroundPositionY = (yperc - 9) + '%';

style.left = (x - 180) + 'px';
style.top = (y - 180) + 'px';

}, false);
}();
</script>

Customization:

No need to customize it. Just copy-paste. Rest edit the code as per comments and need.

Troubleshooting the Errors:

Do it with concentration and patience. Check your all steps again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us If you have any doubts or problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave.

Recommended For You:
Simple Pure HTML-CSS Single Level Top Drop Down Menu

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

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