(1)本节知识点
- mySwiper.width 与 mySwiper.height
- mySwiper.translate
- mySwiper.activeIndex
- mySwiper.previousIndex
常用回调
- 滑屏开始触发
– onSlideChangeStart
- 滑屏结束后触发
– onSlideChangeEnd
(2) 代码开始
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<link rel="stylesheet" href="css/swiper.min.css" />
<script src="js/swiper.min.js"></script>
</head>
<style>
* {
margin: 0px;
padding: 0px;
}
.swiper-container {
width: 350px;
height: 300px;
}
.swiper-slide {
font-size: 50px;
}
.swiper-slide {
background: yellow;
}
</style>
<body>
<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>
</div>
<button id="btn">按钮</button>
</body>
<script>
window.onload = function () {
var mySwiper = new Swiper('.swiper-container', {
direction: 'horizontal',
speed: 4000,
onSlideChangeStart: function () {
console.log('开始滑动')
},
onSlideChangeEnd: function () {
console.log('滑动结束')
},
})
document.querySelector('#btn').onclick = function () {
console.log(mySwiper)
console.log(mySwiper.width)
console.log(mySwiper.height)
console.log(mySwiper.translate)
console.log(mySwiper.activeIndex)
console.log(mySwiper.previousIndex)
}
}
</script>
</html>