Swiper pause autoplay - Barrierefreiheit
Hey,
ich habe dem Standard-Slider für Contao eine Pause-Funktion nach dieser Vorlage hinzugefügt.
https://devspaceblog.com/creating-ac...swiper-slider/
Ich denke, dass wegen der Barrierefreiheit das auch andere gut gebrauchen können.
1. Custom swiper Twig template anlegen - content_element/swiper/swiper_pause.html.twig
HTML-Code:
{% extends "@Contao/content_element/swiper.html.twig" %}
{% block controls %}
{{ parent() }}
<button class="dsb-button-control" aria-pressed="false">
<span class="screen-reader-text">Pause</span>
<span class="dashicons dashicons-controls-pause"></span>
</button>
{% endblock %}
{% block init_options %}
{{ parent() }}
on: {
afterInit: function (dsb_slider) {
// Play/Pause control button
const controlBtn = document.querySelector('.dsb-button-control');
controlBtn.addEventListener('click', function () {
if (this.getAttribute('aria-pressed') === 'false') {
dsb_slider.autoplay.stop();
this.querySelector('.screen-reader-text').textContent = 'Play';
this.querySelector('.dashicons').classList.remove('dashicons-controls-pause');
this.querySelector('.dashicons').classList.add('dashicons-controls-play');
this.setAttribute('aria-pressed', 'true');
} else {
dsb_slider.autoplay.start();
this.querySelector('.screen-reader-text').textContent = 'Pause';
this.querySelector('.dashicons').classList.remove('dashicons-controls-play');
this.querySelector('.dashicons').classList.add('dashicons-controls-pause');
this.setAttribute('aria-pressed', 'false');
}
});
},
},
{% endblock %}
2. CSS für Button anlegen:
HTML-Code:
.dsb-button-control {
position: absolute;
bottom: 8px;
z-index: 10;
right: 10px;
}
3. Contao Prod.-Cache erneuern
4. Swiper Inhaltselement im Backend anlegen und das Template swiper_pause.html.twig auswählen.