Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what is the code for...
when we click on a particular image it display larger view
Posted
Comments
Member 8570559 27-Feb-12 1:52am    
Check out
http://www.dynamicdrive.com/dynamicindex4/imagemagnify.htm
Sergey Alexandrovich Kryukov 27-Feb-12 2:14am    
Looks like an interesting and useful piece of code -- you could post it as an answer.
--S

Have a look at image controls with zoom functionality -
ASP.NET Image Manipulation Examples: Adding, Zooming, Enlarging[^]
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/Seadragon/Seadragon.aspx[^]

Ajax Zoom[^] is an interesting third party you could look at.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Feb-12 2:06am    
Good information, my 5.

I still think my minimalistic sample has the benefits of explaining the basics ideas in a very compact and simple way. It also can be enough for a particular purpose -- please see.
--SA
Abhinav S 27-Feb-12 2:08am    
Thank you SA.
I would advise to use jQuery library for a very simple solution. Something like that:

XML
<html>
<head>
    <title>...</title>
    <script type="text/javascript" src="scripts/jquery-1.7.1.min.js"></script>
</head>
<body>

    <img alt="Image" id="image" />

    <script type="text/javascript">

        $(document).ready(function() {
            imageElement = $("#image");
            imageElement.attr("src", "small.png");
            imageElement.hover(
                function() {
                    $(this).attr("src", "big.png");
                },
                function() {
                    $(this).attr("src", "small.png");
                }
            );
        });

    </script>

</body>
</html>


In this code sample, I assume you use a big version of the image, "big.png", and a small one, created by re-sampling a big one down, "small.png". At first, your element img does not show any image. When the document is loaded and its DOM is ready, a small one is installed and then the images are swapped on the events of hovering into and out of the image.

I did not use the click event, as you did not explain on what event should you make the image small again. If you want to use the event onclick, use the jQuery event click, with only one method argument (handler). Please see:
http://api.jquery.com/click/[^].

For understanding of the rest of this code, please see:
http://api.jquery.com/attr/[^],
http://api.jquery.com/category/selectors/[^],
http://api.jquery.com/category/events/[^],
http://api.jquery.com/ready/[^].

For more information on jQuery, please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://docs.jquery.com/Main_Page[^].

—SA
 
Share this answer
 
v6
Comments
Abhinav S 27-Feb-12 2:09am    
That is an accurate answer. My 5.
Sergey Alexandrovich Kryukov 27-Feb-12 2:12am    
Thank you, Abhinav.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900