Enlarge an image by clicking

0

Having a "thumbnail" image in HTML as follows:

<img src="recursos/calle.jpg" width="80px" height="90px"/>

How can I do so that when I click on it it enlarges in the form of a full view on the screen?

    
asked by omaza1990 10.02.2018 в 14:10
source

1 answer

3

I think what you're looking for is to make a kind of modal window. With Javascript you can do it, you just need to adapt the following code

// Get the modal
var modal = document.getElementById('myModal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
    modal.style.display = "none";
}

Source: How TO - Modal Images (w3schools)

    
answered by 10.02.2018 / 15:09
source