I solved my problem with a little effort. I used javascript to solve it. I also added caption on my images. I edited the div class like this:
<div class="someClass" data-target="#myModal" data-toggle="modal"
onclick='changeImage("image.jpg"); changeCaption("o");' style="background-image: url(image.jpg)"></div>
At the end of the page, I added my modal;
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<img src="" class="img-responsive" id="modalImg">
<p id="imgalt" class="caption"></p>
</div>
</div>
</div>
</div>
So as you see, <img src>
and <p>
tags are empty. I fill these with a little javascript code. Let's see that too:
<script type="text/javascript">
function changeImage(a) {
document.getElementById("modalImg").src = a;
}
function changeCaption(id) {
var img = document.getElementById(id);
if (id === "o") {
document.getElementById("imgalt").innerHTML = " ";
}
else {
document.getElementById("imgalt").innerHTML = id;
}
}
</script>
Here, each ID is really important. Make sure you make them same.
So changeImage(a)
function changes the image. In my div tag, I made it to open "image.jpg".
changeCaption(id)
function changes the caption. If you want no caption, you write changeCaption("o");
as I wrote in my div class. If you want your caption to be "Beautiful Flowers", for example, you write changeCaption("Beautiful Flowers");
.
I hope I helped someone. Thanks.