Using Bootstrap classes and the swiper JS tool, can you please convert the following…
- User
Using Bootstrap classes and the swiper JS tool, can you please convert the following code (for mobile only, desktop is fine as it is now!) into a slider? Also please put the pagination dots at the bottom. It should be automatic scrolling.
- Assistant
Sure! Please provide the code you want me to convert into a slider for mobile only using Bootstrap and Swiper.js. Once I have it, I can help you add the slider functionality with pagination dots at the bottom and automatic scrolling on mobile devices.
- User
Oh, sorry! Here it is:
- Assistant
- User
please modify the code so it shows 3 at the same time:
codedocument.addEventListener('DOMContentLoaded', function () { new Swiper('.swiper-container', { slidesPerView: 'auto', spaceBetween: 16, loop: true, autoplay: { delay: 3000, disableOnInteraction: false, }, pagination: { el: '.swiper-pagination', clickable: true, }, }); }); - Assistant
Sure! To show 3 slides at the same time, change
slidesPerViewfrom'auto'to3. Here is your modified JS code snippet:jsdocument.addEventListener('DOMContentLoaded', function () { new Swiper('.swiper-container', { slidesPerView: 3, // show 3 slides at once spaceBetween: 16, loop: true, autoplay: { delay: 3000, disableOnInteraction: false, }, pagination: { el: '.swiper-pagination', clickable: true, }, }); });
Optional: Responsive behavior on smaller mobiles
If you want the slider to show fewer slides on very small screens (e.g. 1 or 2), you can add
breakpointslike this:js - User
The pagination dots should be white and be inside of the black container:
code<!-- Mobile --> <div class="swiper-container d-flex d-lg-none"> <div class="swiper-wrapper"> <?php if($icons) { foreach($icons as $icon) { $main = $icon['main']; $hover = $icon['hover']; $label = $icon['label']; $link = $icon['link']; ?> <a href="<?php echo $link;?>" class="swiper-slide d-block text-center" style="width:auto;"> <div class="image-wrapper"> <img src="<?php echo bcb_image_url($main);?>" alt="<?php echo $label;?>" class="w-25 main-img p-0"/> <img src="<?php echo bcb_image_url($hover);?>" alt="<?php echo $label;?>" class="w-25 hover-img p-0"/> </div> <p class="mb-0 text-white fs-4 nowrap"><?php echo $label;?></p> </a> <?php }}?> </div> <div class="swiper-pagination mt-3"></div> </div> - Assistant