I am trying to use Swiper but I cannot achieve it, I followed the steps in the documentation (https://swiperjs.com/get-started/), the problem is that all the images / slides are mixed together, it allows me to slide to the side but since all the images are together it does not work. It shows me a slide with all the content, which I can slide but it has nothing on the sides. I'm doing it in ngOnlnit, at first not even the swiped worked correctly, but when I added setTimeout to delay the creation of var swiper it started to work (the swiped only)
component.ts:
import 'swiper/swiper-bundle.css';
import Swiper, { Navigation, Pagination } from 'swiper';
@Component({
selector: 'app-sing-accesorios',
templateUrl: './sing-accesorios.component.html',
styleUrls: ['./sing-accesorios.component.css']
})
export class SingAccesoriosComponent implements OnInit {
constructor(){
Swiper.use([Navigation, Pagination]);
}
ngOnInit(): void {
setTimeout(function(){
var swiper = new Swiper('.swiper-container');
},500)
}
}
component.html:
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
<div class="swiper-slide">Slide 5</div>
<div class="swiper-slide">Slide 6</div>
<div class="swiper-slide">Slide 7</div>
<div class="swiper-slide">Slide 8</div>
<div class="swiper-slide">Slide 9</div>
<div class="swiper-slide">Slide 10</div>
</div>
</div>
component.css:
.swiper-container {
width: 100%;
height: 100px;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}