Tuesday, July 5, 2011

JQuery Hover Image Zoom





This is zooming hovered image. it can be use in image gallery or simple zoom effect on any image.


1. Here we need a file called jquery-1.6.1.min.js, Click Here to download


2.HTML Code:

<!DOCTYPE html>
<html>
<head>
    <title>JQuery Zoom Hover</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="jquery-1.6.1.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        var cont_left = $("#container").position().left;
        $("a img").hover(function() {
            // hover in
            $(this).parent().parent().css("z-index", 1);
            $(this).animate({
               height: "250",
               width: "250",
               left: "-=50",
               top: "-=50"
            }, "fast");
        }, function() {
            // hover out
            $(this).parent().parent().css("z-index", 0);
            $(this).animate({
                height: "150",
                width: "150",
                left: "+=50",
               top: "+=50"
            }, "fast");
        });
 
        $(".img").each(function(index) {
            var left = (index * 160) + cont_left;
            $(this).css("left", left + "px");
        });
    });
    </script>
    <style type="text/css">
        #container {
            text-align: center;
            position: absolute;
            left: 260px;
            margin-top: 150px;
            width: 790px;
        }
        .img {
            position: fixed;
            z-index: 0;
        }
        .end {
            margin-right: 0;
        }
        .clear {
            clear: both;
        }
        .img a img {
            position: relative;
             border: 0 solid #fff;
        }
    </style>
</head>
<body>
    <div id="container">
        <div class="img"><a href="#"><img src="images/1.jpg"/></a></div>
        <div class="img"><a href="#"><img src="images/2.jpg"/></a></div>
        <div class="img"><a href="#"><img src="images/3.jpg"/></a></div>
        <div class="img"><a href="#"><img src="images/4.jpg"/></a></div>
        <div class="img end"><a href="#"><img src="images/5.jpg"/></a></div>
        <div class="clear"></div>
    </div>
</body>
</html>

0 comments:

Post a Comment