滑动滑块:滑动更改为其他 div
Swiper slider: slide change to other div
我创建了一个视差滑块,但我在更改滑块时遇到了一个大问题。当我的鼠标在蓝色区域内时,我可以更改滑块
正如你所理解的蓝色区域(或蓝色块)是swiper-wrapper
class,我可以将height
设置为100%
,但是在这个万一我的布局被破坏了。
我想知道 swiper-slider 是否为我提供了这样一个 属性 以便我可以在蓝色区域之外(或 swiper-wrapper
)?
如果您想在每张幻灯片中创建一些 space,请在滑动器幻灯片中添加额外的 div。 ** space.
最好使用 % 而不是 px
片段示例:
const swiper = new Swiper('.swiper', {
// Optional parameters
loop: false,
centeredSlidesBounds: true,
slidesPerView: 2.1,
spaceBetween: 20,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
});
.swiper {
width: 100%;
height: 100%;
}
.card_inside_swiper{
background: red;
max-width: 90%;
margin: 0px auto;
}
<link
rel="stylesheet"
href="https://unpkg.com/swiper@8/swiper-bundle.min.css"
/>
<style>
.swiper-slide {
background: #2196f3;
height: auto;
}
</style>
<!-- Slider main container -->
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide" data-city="london"><div class="card_inside_swiper"><p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p></div></div>
<div class="swiper-slide" data-city="london"><div class="card_inside_swiper"><p>hello</p></div></div>
<div class="swiper-slide" data-city="london"><div class="card_inside_swiper"><p>hello</p></div></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>
</div>
<script src="https://unpkg.com/swiper@8/swiper-bundle.min.js"></script>
我创建了一个视差滑块,但我在更改滑块时遇到了一个大问题。当我的鼠标在蓝色区域内时,我可以更改滑块
正如你所理解的蓝色区域(或蓝色块)是swiper-wrapper
class,我可以将height
设置为100%
,但是在这个万一我的布局被破坏了。
我想知道 swiper-slider 是否为我提供了这样一个 属性 以便我可以在蓝色区域之外(或 swiper-wrapper
)?
如果您想在每张幻灯片中创建一些 space,请在滑动器幻灯片中添加额外的 div。 ** space.
最好使用 % 而不是 px片段示例:
const swiper = new Swiper('.swiper', {
// Optional parameters
loop: false,
centeredSlidesBounds: true,
slidesPerView: 2.1,
spaceBetween: 20,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
});
.swiper {
width: 100%;
height: 100%;
}
.card_inside_swiper{
background: red;
max-width: 90%;
margin: 0px auto;
}
<link
rel="stylesheet"
href="https://unpkg.com/swiper@8/swiper-bundle.min.css"
/>
<style>
.swiper-slide {
background: #2196f3;
height: auto;
}
</style>
<!-- Slider main container -->
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide" data-city="london"><div class="card_inside_swiper"><p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p></div></div>
<div class="swiper-slide" data-city="london"><div class="card_inside_swiper"><p>hello</p></div></div>
<div class="swiper-slide" data-city="london"><div class="card_inside_swiper"><p>hello</p></div></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>
</div>
<script src="https://unpkg.com/swiper@8/swiper-bundle.min.js"></script>