Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html zoom on mouse over

I want to have a photo in a site, and when I mouse over, I want a little magnifier zoom effect.

Can I do this in html with canvas or something? javascript maybe?

thank you

like image 993
pvinis Avatar asked Feb 09 '11 01:02

pvinis


People also ask

How do I zoom my mouse over?

Zoom images/videos on all your favorite websites (Facebook, Amazon, etc). Simply hover your mouse over the image to enlarge it. Hover your mouse over any image on the supported websites and the extension will automatically enlarge the image to its full size, making sure that it still fits into the browser window.

How do I make my mouse hover in HTML?

The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.

How do you zoom text in HTML?

Wrap your text in a span that has display: inline-block in order to zoom in on the center of the text instead. Also, the website you linked has the text fade in/out as well. Add opacity: 0 to your span to make it invisible, and then have it transition to opacity: 1 on :hover to achieve this fade in/out effect.

How do I change the image on my mouse over in HTML?

Answer: Use the CSS background-image property You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.


2 Answers

Enclose your photo in a div and add Zoom via CSS on hover. You may want to increase the z-index upon hover. You can add to the below CSS to make the zoomed photo look/style better. If you don't want to reinvent the wheel, look out for some Jquery plugin which may accomplish the same thing in an elegant manner with less effort.

CSS:

#div-1 {
            position: absolute;
        }
#div-1.hover {
            position: absolute; zoom: 70%; border: solid 1px; z-index:10;
        }

Jquery/Javascript:

          <script type = "text/javascript"> 
$(document).ready(function() {
$(".div-1").onmouseover(function() {
    toggle_visibility('div-1');
})

function toggle_visibility(id) {
    var e = document.getElementById(id);
    if ($(e).hasClass("hover")) {
        $(e).removeClass("hover");
    } else {
        $($(e)).addClass("hover");
        $($(e)).attr({
            width: "100%",
            height: "100%"
        });
    }
}}); < /script>
like image 95
Piyush Mattoo Avatar answered Sep 18 '22 13:09

Piyush Mattoo


Canvas isn't supported by IE without third-party plug-ins. You'll want to do this in JavaScript. jQuery makes this very easy and clean. Bind handlers for the hover in / out events for the image element you want to zoom using .hover(). "Binding handlers" simply means you pass two functions to .hover() which will be executed when the user hovers in and out, respectively. These functions will use animate(), which you can simply pass a new size.

Have a look at the documentation for .animate() and .hover(). If you're totally new to jQuery, check out the tutorials.

like image 31
Ori Avatar answered Sep 21 '22 13:09

Ori