I have this code <section class="pricing"> <div class="pricing-container"> <div…
- User
I have this code
</div></div></div>.pricing-column { flex: 1 0 100% !important; min-width: 300px !important; scroll-snap-align: start !important; }
My goal is for the mobile version of the site to add the swiper buttons to the above. Like the one below:
- Assistant
To add the swiper buttons to the pricing section in the mobile version of the site, you can modify the HTML code as follows:
<section class="pricing"> <div class="swiper-container pricing-container"> <div class="swiper-wrapper"> <div class="swiper-slide pricing-column column-1"> CONTENUTI </div> <div class="swiper-slide pricing-column column-2"> CONTENUTI </div> <div class="swiper-slide pricing-column column-3"> CONTENUTI </div> </div> <div class="elementor-swiper-button elementor-swiper-button-prev" role="button" tabindex="0"> <i aria-hidden="true" class="eicon-chevron-left"></i> <span class="elementor-screen-only">Previous</span> </div> <div class="elementor-swiper-button elementor-swiper-button-next" role="button" tabindex="0"> <i aria-hidden="true" class="eicon-chevron-right"></i> <span class="elementor-screen-only">Next</span> </div> </div> </section>Then, you can use JavaScript to initialize the swiper and its options:
var swiper = new Swiper('.pricing-container', { slidesPerView: 'auto', spaceBetween: 20, navigation: { nextEl: '.elementor-swiper-button-next', prevEl: '.elementor-swiper-button-prev', }, });Make sure you have included the Swiper library in your project.
- User
I changed the html, but there has to be somthing wrong cause the site doesn't work
- Assistant
There could be several reasons why the site is not working after making the HTML changes:
-
Missing Swiper library: Make sure you have included the Swiper library in your project. You can either download it and include the CSS and JS files in your project, or use a CDN to include the library.
-
Incorrect initialization code: Check if you have correctly initialized the Swiper using JavaScript. The code to initialize Swiper should be placed after the Swiper library has been loaded and the HTML has been rendered. You can wrap the initialization code within the
DOMContentLoadedevent listener to ensure it runs after the HTML has loaded:
document.addEventListener('DOMContentLoaded', function() { var swiper = new Swiper('.pricing-container', { slidesPerView: 'auto', spaceBetween: 20, navigation: { nextEl: '.elementor-swiper-button-next', prevEl: '.elementor-swiper-button-prev', }, }); });- CSS conflicts or errors: Check if there are any CSS conflicts or errors that may be causing issues with the layout or functionality. Make sure all the CSS classes and styles are applied correctly, and there are no syntax errors or conflicting styles that may disrupt the rendering of the page.
Inspect the browser's console for any error messages that may provide more information about the issue. Additionally, make sure to test the site on different devices and browsers to ensure cross-compatibility.
-
- User
Where do I have to paste this?
- Assistant
The JavaScript code for initializing the Swiper should be placed within a
<script>tag in your HTML file. You can paste it just before the closing</body>tag or within the<head>tag.Here's an example of where you can place the initialization code within the
<script>tag:<script src="path/to/swiper.js"></script> <script> document.addEventListener('DOMContentLoaded', function() { var swiper = new Swiper('.pricing-container', { slidesPerView: 'auto', spaceBetween: 20, navigation: { nextEl: '.elementor-swiper-button-next', prevEl: '.elementor-swiper-button-prev', }, }); }); </script>Make sure to replace
path/to/swiper.jswith the actual path to the Swiper library file or use a CDN link for the library. - User
Sorry, where do I have to paste this
document.addEventListener(‘DOMContentLoaded’, function() { var swiper = new Swiper(‘.pricing-container’, { slidesPerView: ‘auto’, spaceBetween: 20, navigation: { nextEl: ‘.elementor-swiper-button-next’, prevEl: ‘.elementor-swiper-button-prev’, }, }); });
- Assistant
The
document.addEventListener('DOMContentLoaded', function() { ... });code block should be placed within a<script>tag in your HTML file, just before the closing</body>tag or within the<head>tag.Here's an example of where you can paste the code within the
<script>tag:<script src="path/to/swiper.js"></script> <script> document.addEventListener('DOMContentLoaded', function() { var swiper = new Swiper('.pricing-container', { slidesPerView: 'auto', spaceBetween: 20, navigation: { nextEl: '.elementor-swiper-button-next', prevEl: '.elementor-swiper-button-prev', }, }); }); </script>Remember to replace
path/to/swiper.jswith the actual path to the Swiper library file or use a CDN link for the library. - User
The code look like this now. Where's the problem?
<div class=“elementor-swiper-button elementor-swiper-button-next” role=“button” tabindex=“0”> <i aria-hidden=“true” class=“eicon-chevron-right”></i> <span class=“elementor-screen-only”>Next</span> </div> <script>document.addEventListener(‘DOMContentLoaded’, function() { var swiper = new Swiper(‘.pricing-container’, { slidesPerView: ‘auto’, spaceBetween: 20, navigation: { nextEl: ‘.elementor-swiper-button-next’, prevEl: ‘.elementor-swiper-button-prev’, }, }); });
- Assistant
The initialization code you provided is almost correct. However, the issue lies in the use of incorrect quotation marks around the event listener and the element selectors. In JavaScript, you should use straight single (
' ') or double (" ") quotation marks, but the ones in your code are curly (‘ ’) and (“ ”).Here's the corrected version of your code:
<section class="pricing"> <div class="swiper-container pricing-container"> <div class="swiper-wrapper"> <!-- Pricing Column 1 --> <div class="swiper-slide pricing-column column-1"> <!-- Pricing content here --> </div> <!-- Pricing Column 2 --> <div class="swiper-slide pricing-column column-2"> <!-- Pricing content here --> </div> <!-- Pricing Column 3 --> <div class="swiper-slide pricing-column column-3"> <!-- Pricing content here --> </div> </div> <div class="elementor-swiper-button elementor-swiper-button-prev" role="button" tabindex="0"> <i aria-hidden="true" class="eicon-chevron-left"></i> <span class="elementor-screen-only">Previous</span> </div> <div class="elementor-swiper-button elementor-swiper-button-next" role="button" tabindex="0"> <i aria-hidden="true" class="eicon-chevron-right"></i> <span class="elementor-screen-only">Next</span> </div> </div> </section> <script src="path/to/swiper.js"></script> <script> document.addEventListener('DOMContentLoaded', function() { var swiper = new Swiper('.pricing-container', { slidesPerView: 'auto', spaceBetween: 20, navigation: { nextEl: '.elementor-swiper-button-next', prevEl: '.elementor-swiper-button-prev', }, }); }); </script>Make sure to replace
'path/to/swiper.js'with the correct path to the Swiper library file or use a CDN link to include the library. Additionally, ensure that you have correctly added the Swiper library in your project.