how to click on image so view large

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ahtisham
    New Member
    • Oct 2013
    • 1

    how to click on image so view large

    <img src="http://example.com/images/gallery_3.png" />
    Last edited by Dormilich; Oct 22 '13, 08:35 PM.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Lightbox ?

    Comment

    • Sherin
      New Member
      • Jan 2020
      • 77

      #3
      Try This Code

      Code:
      <!DOCTYPE html>
      <html>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
      <body>
      
      <div class="w3-container">
        <h2> Image Gallery</h2>
        <p>Click on the images to display them in full size.</p>
      </div>
      
      <div class="w3-row-padding">
        <div class="w3-container w3-third">
          <img src="img_snowtops.jpg" style="width:100%;cursor:pointer" 
          onclick="onClick(this)" class="w3-hover-opacity">
        </div>
        <div class="w3-container w3-third">
          <img src="img_lights.jpg" style="width:100%;cursor:pointer" 
          onclick="onClick(this)" class="w3-hover-opacity">
        </div>
        <div class="w3-container w3-third">
          <img src="img_mountains.jpg" style="width:100%;cursor:pointer" 
          onclick="onClick(this)" class="w3-hover-opacity">
        </div>
      </div>
      
      <div id="modal01" class="w3-modal" onclick="this.style.display='none'">
        <span class="w3-button w3-hover-red w3-xlarge w3-display-topright">&times;</span>
        <div class="w3-modal-content w3-animate-zoom">
          <img id="img01" style="width:100%">
        </div>
      </div>
      
      <script>
      function onClick(element) {
        document.getElementById("img01").src = element.src;
        document.getElementById("modal01").style.display = "block";
      }
      </script>
                  
      </body>
      </html>

      Comment

      • SwissProgrammer
        New Member
        • Jun 2020
        • 220

        #4
        Sherin,

        Nice.


        Ahtisham,

        You might want to refresh the elements as soon as they are removed so that they zoom in each time that they are clicked. Currently they zoom in the first time, then after being clicked on and removed they simply show up without the zoom. Sherin gave you some nice code. Let us see how you create that new-zoom effect each time that the same one is clicked.

        Thanks.

        Comment

        Working...