admin管理员组文章数量:1406937
I want to show some image in a thumbnail gallery in which if you click an image then it will appear larger in a modal.
If i keep the link of the modal as an image then it does not show anything at header or footer other than the close sign in top right corner.
I am using bootstrap. I also want to know if i could replace the img
tag to <a>
tag to open the modal section. Please help.
Here is the code:
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<img id="image-modal" class="img-responsive img-rounded" src="<?php echo base_url();?>img/Desert.jpg" data-target="#myModal" data-toggle="modal" alt="">
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<img class="img-responsive" src="<?php echo base_url();?>img/Desert.jpg" alt="">
</div>
<div class="modal-footer">
<p>This is footer</p>
</div>
</div>
</div>
</div>
</div>
I want to show some image in a thumbnail gallery in which if you click an image then it will appear larger in a modal.
If i keep the link of the modal as an image then it does not show anything at header or footer other than the close sign in top right corner.
I am using bootstrap. I also want to know if i could replace the img
tag to <a>
tag to open the modal section. Please help.
Here is the code:
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<img id="image-modal" class="img-responsive img-rounded" src="<?php echo base_url();?>img/Desert.jpg" data-target="#myModal" data-toggle="modal" alt="">
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<img class="img-responsive" src="<?php echo base_url();?>img/Desert.jpg" alt="">
</div>
<div class="modal-footer">
<p>This is footer</p>
</div>
</div>
</div>
</div>
</div>
Share
Improve this question
edited Nov 16, 2015 at 17:05
Shehary
9,99010 gold badges46 silver badges75 bronze badges
asked Nov 16, 2015 at 16:34
Erfan BasharErfan Bashar
1491 silver badge9 bronze badges
3 Answers
Reset to default 3Use modal event listener and pass the image to modal
Script
$(document).ready(function () {
$('#myModal').on('show.bs.modal', function (e) {
var img = $(e.relatedTarget).attr('src'); // get image
$('#showimg').attr('src' , img); //load image in modal
});
});
add id="showimg"
to image tag <img>
in Modal Body
<div class="modal-body">
<img class="img-responsive" src="" alt="" id="showimg">
</div>
Fiddle with <img>
tag
Yes you can also do it with <a>
tag
<a>
tag
<a class="btn btn-primary btn-xs" href="imagepath" data-target="#myModal" data-toggle="modal">Open Image</a>
and event listener script will be
$(document).ready(function () {
$('#myModal').on('show.bs.modal', function (e) {
var img = $(e.relatedTarget).attr('href'); // get image with <a> tag
$('#showimg').attr('src' , img); //load image in modal
});
});
Fiddle with <a>
tag
You can do it with Bootstrap only, but this is what seems like it'd help for what you want to do: https://blueimp.github.io/Bootstrap-Image-Gallery/
I use it on a few websites of mine exactly for this case.
try this Bootstrap-Image-Gallery plugin will help you. check Demo.
本文标签:
版权声明:本文标题:javascript - how could I create a modal with a image in it and the link of the modal is the image itself (on a smaller version)) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745052723a2639750.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论