UNPKG

644 BJavaScriptView Raw
1export default function prependSlide(slides) {
2 const swiper = this;
3 const {
4 params,
5 $wrapperEl,
6 activeIndex
7 } = swiper;
8
9 if (params.loop) {
10 swiper.loopDestroy();
11 }
12
13 let newActiveIndex = activeIndex + 1;
14
15 if (typeof slides === 'object' && 'length' in slides) {
16 for (let i = 0; i < slides.length; i += 1) {
17 if (slides[i]) $wrapperEl.prepend(slides[i]);
18 }
19
20 newActiveIndex = activeIndex + slides.length;
21 } else {
22 $wrapperEl.prepend(slides);
23 }
24
25 if (params.loop) {
26 swiper.loopCreate();
27 }
28
29 if (!params.observer) {
30 swiper.update();
31 }
32
33 swiper.slideTo(newActiveIndex, 0, false);
34}
\No newline at end of file