Function call within ModalBox

1

My idea is as follows, I'm opening an image in a modalBox (or Box image, sorry to say something incorrect because I'm new to the subject) in javascript, how do I call the zoom function after calling the modal box function?

Thank you.

Below is the code I am using:

running here

<span class='zoom' id='ex3'>
   <img id="myImg" src="img/map1.jpg" alt="Trolltunga, Norway" width="300" height="200">
   <p>Hover</p>
</span>


<div id="myModal" class="modal">
   <span class="close">&times;</span>
   <img class="modal-content" id="img01">
   <div id="caption"></div> 
</div>

Javascript:

// 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");
var
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";
}

And this is the function I want to call:

Speak you want this function: // Zoom function

$(document).ready(function(){
    $('#ex3').zoom({ on:'click' });
});

// End of Function

    
asked by anonymous 31.01.2017 / 14:29

1 answer

0

The problem with your code is that you are calling the plugin zoom mal: the documentation says you have to add the event zooms to an element other than an img tag

So, changing your modal html to:

<div id="myModal" class="modal">
   <span class="close">&times;</span>
   <div class="zoom"><img class="modal-content" id="img01"></div>
   <div id="caption"></div> 
</div>

And changing your function from onclick to:

img.onclick = function() {
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
    $('.zoom').zoom({
      on: 'click',
      url: this.src
    });
  }

zoom in

    
31.01.2017 / 15:29