Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  179] [ 6]  / answers: 1 / hits: 57148  / 11 Years ago, sun, july 7, 2013, 12:00:00

I am applying the idangerous swiper scrollbar plugin on a container whose content is dynamically loaded with ajax, I initialize the plugin after the ajax call, the issue is that the scroll doesn't work until I resize the browser. I have tested it with static content it's working fine, no need to resize the window but once I switch to dynamic content, the scroll won't work unit I resize the browser.



Here's how am initializing the plugin



var mySwiper = new Swiper('.swiper-container', {
scrollContainer: true,
mousewheelControl: true,
mode: 'vertical',
scrollbar: {
container: '.swiper-scrollbar',
hide: true,
draggable: false
}
});


here's the html



<div class=swiper-container>
<div class=swiper-wrapper>
<div class=swiper-slide>
<div class=searchList>
//here's the dynamic content being loaded (a list of div elements)
</div>
</div>
</div>
<div class=swiper-scrollbar>
</div>
</div>


swiper-container height is 100%


More From » swiper.js

 Answers
21

I found the solution, I added this function which I call after first initializing the plugin



function reinitSwiper(swiper) {
setTimeout(function () {
swiper.reInit();
}, 500);
}


This fix was mentioned in another plugin and when I tried it with this swiper plugin it worked. It has something to do with the plugin not aware of the change that occurred to the DOM.


[#77150] Friday, July 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ernest

Total Points: 332
Total Questions: 92
Total Answers: 98

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
ernest questions
Sat, Jun 12, 21, 00:00, 3 Years ago
Tue, Sep 22, 20, 00:00, 4 Years ago
;