LATEST >>

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

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / JavaScript Codes » Image Zoom on Hover with Pure JavaScript & CSS

Image Zoom on Hover with Pure JavaScript & CSS

Image-Zoom-On-Mouse-Hover-And-On-Touch-Using-Pure-JavaScript
Image Zoom on Hover makes the image slider or gallery much more interesting and suitable. You can easily create an image zoom using only HTML and CSS. However, some amount of JavaScript has been used here.

In this article, I have shown how to make an image zoom using JavaScript and CSS. Earlier I made many more designs in image galleries and sliders. You can see those designs.

Basically it will follow your mouse cursor. As a result, the part of the image where you move the mouse will be zoomed in. But it is not possible to just zoom the image with CSS.

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.
Recommended For You:
Smooth Scroll To A Desired Up Or Down DIV OnClick Via Pure JavaScript

How To Create Simple And Rich Toast-Style Web Notifications In Vanilla JavaScript?

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

CSS:

<style type="text/css">
figure.zoom {
background-position: 50% 50%;
position: relative;
margin: 150px auto;
border: 5px solid white;
box-shadow: -1px 5px 15px black;
height: 300px;
width: 500px;
overflow: hidden;
cursor: zoom-in;
}
figure.zoom img:hover {
opacity: 0;
}
figure.zoom img {
transition: opacity 0.5s;
display: block;
width: 100%;
}
</style>

HTML:

<figure class="zoom" onmousemove="zoom(event)" style="background-image: url(https://i.pinimg.com/originals/2b/de/de/2bdede0647e3cdf75b44ea33723201d9.jpg)">
<img src="https://i.pinimg.com/originals/2b/de/de/2bdede0647e3cdf75b44ea33723201d9.jpg" />
</figure>

JavaScript:

<script type="text/javascript">
function zoom(e){
var zoomer = e.currentTarget;
e.offsetX ? offsetX = e.offsetX : offsetX = e.touches[0].pageX
e.offsetY ? offsetY = e.offsetY : offsetX = e.touches[0].pageX
x = offsetX/zoomer.offsetWidth*100
y = offsetY/zoomer.offsetHeight*100
zoomer.style.backgroundPosition = x + '% ' + y + '%';
}
</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:
How To Lock Your Site/Blog From Being Used In An IFrame?

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 *