I have dynamic link and each link is associated with modal pop up.
@foreach($image_data as $image)
<a href="#" data-toggle="modal" data-target="#{{$image->image_id}}">
<img src="{{asset('public/user_images/')}}/{{$image->image_name}}">
</a>
<div class="modal fade" id="{{$image->image_id}}" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">X</span></button>
<div class="modal-body">
<img src="{{asset('public/user_images/')}}/{{$image->image_name}}">
</div>
</div>
</div>
</div>
@endforeach
What javascript or something else should I use to pop up this model ?
$('.buttonClass').on('click', function(){
$('#modalID').fadeIn();
});
<button type="button" class="open" data-dismiss="modal" data-id={{$image->image_id}}>
And then in JavaScript add
$('.buttonClass').on('click', function(){
let modalID = '#' + $(this).data('id');
$(modalId).fadeIn();
});
Add class="modal-open"
to your a
s
jQuery method
$('.modal-open').on('click', function() {
$( '#'+$(this).data('target') ).show();
})
Typing from my head so there could be typos.
If the a
s and .modal
s are added dynamically then:
$(this).on('click','.modal-open', function() { ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.