Расширения Joomla WebTolk
91 Всего расширений
11 Категорий
424 Выпущено версий
422665 Всего скачиваний
Как начать работать со Swiper.js в Joomla.
В нужном php-файле (index.php
вашего шаблона или в php-файле макета (layout) вашего расширения) выполните подключение Swiper.js. Как правило макеты вывода модулей и плагинов находятся в папке tmpl
модуля или плагина. Это может быть, например, путь modules/mod_articles/tmpl или plugins/content/wtcontentimagegallery/tmpl.
<?php
use Joomla\CMS\Factory; // В начале файла
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->useScript('swiper-bundle')->useStyle('swiper-bundle'); // Local file.
$wa->usePreset('swiper-bundle-remote'); // From CDN - get the latest version
Таким образом в код страницы будут подключены JS и CSS файлы swiper.js.
Добавьте разметку Swiper в код страницы:
<!-- Slider main container -->
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
...
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
Можно указывать пользовательские стили и размеры для swiper с помощью CSS.
.swiper {
width: 600px;
height: 300px;
}
Необходимо инициализировать скрипт, чтобы swiper начал работать:
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'vertical',
loop: true,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar',
},
});
Примечание: рекомендую оборачивать инициализацию скрипта в DOMContentLoaded
.
document.addEventListener('DOMContentLoaded', () => {
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'vertical',
loop: true,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar',
},
});
});