Swiper in modal with Ajax
See original GitHub issueHello!
I have problem with loading Swiper in Bootstrap modal with Ajax.
Problem is that slider not working. It seems like slider blocked, pagination have only 1 dot, but in real there are more images downloaded from DB. And next/prev buttons also blocked.
I tried use reInit:
function reinitSwiper(swiper) {
setTimeout(function () {
swiper.reInit();
}, 500);
}
after “$(‘.swiper-container’).swiper({…});” in script.js , but it change nothing
Here my code:
/script.js/
$('#id').on('click', function () {
var ID = $(this).attr('id');
$.ajax({
url: './',
type: 'POST',
data: {ID: ID},
success: function(res){
$(res).appendTo($('body'));
/*Swiper*/
$('.swiper-container').swiper({
pagination: '.swiper-pagination',
paginationClickable: true,
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev'
});
/*Bootstrap modal run*/
$('#myModal').modal('show');
},
error: function(){
alert('Error');
}
});
});
/controller.php/
if(isset($_POST['ID'])){
$ID = $_POST['ID'];
$img = getImgfromDB($dbconn, $ID);
require_once 'modalImg.php';
exit;
}
/modalImg.php/
<div class="modal fade bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header text-center">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class='galleryContent'>
<div class="swiper-container">
<div class="swiper-wrapper">
<?php foreach($img as $item): ?>
<div class="swiper-slide"><img src="_img/<?=$item?>" /></div>
<?php endforeach; ?>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
</div>
</div>
</div>
</div>
Thanks in advance, for your help!
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Swiper in modal with Ajax · Issue #1598
Hello! I have problem with loading Swiper in Bootstrap modal with Ajax. Problem is that slider not working. It seems like slider blocked, ......
Read more >Swiper Ajax Lazy loading test case
$(document). ready(function() { var swiper = new Swiper(". swiper-container", { // Optional parameters effect: "fade", //autoplay: 2500, loop: true, nextButton ...
Read more >Swipe not working when added dynamically via AJAX
Finally I have figured out the underlying issue. As Page B is loaded by Ajax each time, Swipe script is not loaded.
Read more >[Best solution]-Set active slide in modal click on Swiper slider
Im having a table where it has a a button which opens up a modal window and inside the modal there is a...
Read more >VenoBox 2 - Javascript modal window plugin, touch swipe ...
The big difference compared to many others modal-window plugins is that ... Touch Swipe and Arrow Keys navigation enabled ... Gmaps iFrame Ajax...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just discovered that to fix this issue in most of the cases adding:
to the swiper call do the trick.
So from the example above:
thanks wwwwwwoorks !