Function call within Modalbox

Asked

Viewed 60 times

1

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

Thank you.

Below is the code I’m using:

rotating 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:

says Voce wants this function : //Zoom function

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

//End of Function

  • Want to post the code you already tried, and the errors that followed, in your post.

  • Moshmage edited the question and added the code

  • Yes I’m using

1 answer

0


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

So, switching your html from modal 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 for:

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

The image now zoom in

  • It worked!! Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.