Need To Load Image As Modal On Click In Bootstrap Css
I have tried loading a modal image on clicking a image by fading the background. It works for me. But for multiple images how can I load the image which I have clicked based on the
Solution 1:
Try this
HTML
<!-- Image trigger modal -->
<img src="http://sheshtawy.files.wordpress.com/2010/05/extra-firefox.png" class="img-responsive img-thumbnail" style="min-height:300px;height:300px;" alt="Responsive image">
<img src="http://sheshtawy.files.wordpress.com/2013/03/cairo_pollution.jpg?w=250"/>
<img src="http://sheshtawy.files.wordpress.com/2012/12/img_4749.jpg?w=250"/>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<img id="mimg" src="">
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Script
$(window).load(function(){
$('img').on('click',function()
{
var sr=$(this).attr('src');
$('#mimg').attr('src',sr);
$('#myModal').modal('show');
});
});
Post a Comment for "Need To Load Image As Modal On Click In Bootstrap Css"