jquery - Zoom one image from click of some other image -


<div>    <img src="1.jpg">    <img src="2.jpg"> </div>  <div>    <img src="3.jpg">    <img src="4.jpg"> </div> 

requirement - on click of image'2.jpg' image '1.jpg' should zoomed ,on click of image'4.jpg' image'3.jpg' should zoomed , forth .there can number of these div . image 2/4/6 ... dynamic images . images 1/3/5 ... static zoom icon.

$(function() { 

what have done till

$('img').on('click', function() {   $('.zoomimageclass').attr('src', $(this).attr('src'));   $('#zoomimageid').modal('show'); }); 

});

but here clicked image getting zoomed . want image zoomed zoom icon clicked .

<div>   <img class="sourceimageclass" src="http://via.placeholder.com/350x350">   <img class="zoomimageclass" src="http://via.placeholder.com/5x5"> </div>  <div>   <img class="sourceimageclass" src="http://via.placeholder.com/300x300">   <img class="zoomimageclass" src="http://via.placeholder.com/5x5"> </div>  <img id="zoomimageid"> 

and in js

$(function() { $("div img.zoomimageclass").each(function(i,el){     $(el).click(function(){     console.log($(el).attr("src"));   var imageurl=$(el).parent().find(".sourceimageclass").attr("src");   $("#zoomimageid").attr("src", imageurl) }); 

}); });

working fiddle https://jsfiddle.net/hanalulu/trpdqxac/2/

don't forget accept answer , post comments on answer if need more help.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -