Dynamic slidesPerView


#1

When using Slides in a browser ( or possibly device ), the slidesPerView may need to be dynamic to allow for a restriction on how far a user can swipe and how many of the slides can be seen.

The scenario here is a Slides containing a random number of buttons.
The number of buttons ( or slides ) shown depends on the width of the screen ( both in window size and whether splitPane is activated ).

If the wrong number of slidesPerView is set, the user could swipe the buttons away until they are all off screen or they may not be able to reach the last button.

My current Working solution is as follows but - is there not a simpler ( more Ionic ) way?

I call a resize event which grabs the width of the slides using:
var slidesWidth = document.getElementById('catSlides').offsetWidth;

Then set the slidesPerView like this:

this.slider.slidesPerView = slidesWidth/120;

120 is based on my button width.

I should note that I have since gone with using loop BUT this is not an answer to the question.
If I did not want to go with using loop then I think this question is still valid - just less important :wink: