swiper中swiper-pagination中的位置設(shè)置方法
需求:
期望swiper-pagination 導(dǎo)航靠右下角
解決:
可以配置clickableClass這個(gè)屬性,屬性值指定的是你自定義的class類名。
swiper實(shí)例,導(dǎo)航paination,添加clickableCalss屬性:
var mySwiper = new Swiper('.swiper-container',{
pagination:{
el: '.swiper-pagination',
clickable: true,
clickableClass : 'my-pagination-clickable',
},
})然后在css中定義.my-pagination-clickable。
/*增加自定義css class*/
.swiper .my-pagination-clickable {
width: 1200px;
text-align: right;
}根據(jù)我的期望效果是讓導(dǎo)航靠右下角。原css配置樣式寫死了left:0,所有只要把left:0沖掉,然后讓導(dǎo)航在右邊就可。
最終實(shí)現(xiàn)的效果:

html完整源碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Swiper demo</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"
/>
<!-- Link Swiper's CSS -->
<link rel="stylesheet" href="swiper-bundle.min.css">
<!-- Demo styles -->
<style>
html,
body {
position: relative;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
}
.swiper {
width: 1226px;
height: 460px;
}
.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;
}
.swiper-slide img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
/*增加自定義css class*/
.swiper .my-pagination-clickable {
width: 1200px;
text-align: right;
}
</style>
</head>
<body>
<!-- Swiper -->
<div class="swiper mySwiper">
<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>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-pagination"></div>
</div>
<!-- Swiper JS -->
<script src="swiper-bundle.min.js"></script>
<!-- Initialize Swiper -->
<script>
// 初始化輪播圖
let swiper = new Swiper(".mySwiper", {
spaceBetween: 30,
centeredSlides: true,
autoplay: {
delay: 2500,
disableOnInteraction: false,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
pagination: {
el: ".swiper-pagination",
clickable: true,
clickableClass: 'my-pagination-clickable'
},
});
</script>
</body>
</html>頁面刷新導(dǎo)航欄漂移問題
可以參考以下配置試試
/*增加自定義css class*/
.swiper .my-pagination-clickable {
width: auto;
bottom: 26px;
right: 30px;
text-align: right;
}到此這篇關(guān)于swiper中swiper-pagination中的位置怎么設(shè)置的文章就介紹到這了,更多相關(guān)swiper-pagination位置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
- 這篇文章主要介紹了CSS3中的字體及相關(guān)屬性,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2025-06-12
- 本文詳細(xì)解析了CSS3中實(shí)現(xiàn)賬號密碼輸入框提示特效的原理和方法,包括HTML5的placeholder屬性與CSS3新特性如偽類選擇器、動(dòng)態(tài)效果和過渡動(dòng)畫的結(jié)合使用,感興趣的朋友跟隨小2025-05-14
- CSS3的布局特性為前端開發(fā)者提供了無限可能,無論是Flexbox的一維布局還是Grid的二維布局,它們都能夠幫助開發(fā)者以更清晰、簡潔的方式實(shí)現(xiàn)復(fù)雜的網(wǎng)頁布局,本文給大家介紹C2025-05-14
CSS3 Facebook-style Buttons 項(xiàng)目常見問題及最新解決方案
CSS3 Facebook-style Buttons 是一個(gè)開源項(xiàng)目,旨在通過簡單的 CSS 代碼來重現(xiàn) Facebook 按鈕和工具欄的外觀,本文給大家介紹CSS3 Facebook-style Buttons 項(xiàng)目常見問題及2025-05-14使用animation.css庫快速實(shí)現(xiàn)CSS3旋轉(zhuǎn)動(dòng)畫效果
隨著Web技術(shù)的不斷發(fā)展,動(dòng)畫效果已經(jīng)成為了網(wǎng)頁設(shè)計(jì)中不可或缺的一部分,本文將深入探討animation.css的工作原理,如何使用以及其在實(shí)際項(xiàng)目中的應(yīng)用,感興趣的朋友一起看2025-05-14
CSS3 最強(qiáng)二維布局系統(tǒng)之Grid 網(wǎng)格布局
CS3的Grid網(wǎng)格布局是目前最強(qiáng)的二維布局系統(tǒng),可以同時(shí)對列和行進(jìn)行處理,將網(wǎng)頁劃分成一個(gè)個(gè)網(wǎng)格,可以任意組合不同的網(wǎng)格,做出各種各樣的布局,本文介紹CSS3 最強(qiáng)二維布局系2025-02-27- 本文介紹了如何使用CSS3的transform屬性和動(dòng)畫技巧實(shí)現(xiàn)波浪式圖片墻,通過設(shè)置圖片的垂直偏移量,并使用動(dòng)畫使其周期性地改變位置,可以創(chuàng)建出動(dòng)態(tài)且具有波浪效果的圖片墻,同2025-02-27

CSS3模擬實(shí)現(xiàn)一個(gè)雷達(dá)探測掃描動(dòng)畫特效(最新推薦)
文章介紹了如何使用CSS3實(shí)現(xiàn)一個(gè)雷達(dá)探測掃描的效果,包括夜色背景、蜘蛛網(wǎng)盤、掃描體的轉(zhuǎn)動(dòng)效果、尾巴陰影以及被掃描到的光點(diǎn),通過HTML和CSS的配合,實(shí)現(xiàn)了豐富的動(dòng)畫效果,2025-02-21- CSS3的Flexbox是一種強(qiáng)大的布局模式,通過設(shè)置display:flex可以輕松實(shí)現(xiàn)對齊、排列和分布網(wǎng)頁元素,它解決了傳統(tǒng)布局方法中的對齊、間距分配和自適應(yīng)布局等問題,接下來通過本2025-02-19

css3 實(shí)現(xiàn)icon刷新轉(zhuǎn)動(dòng)效果
本文給大家介紹css3 實(shí)現(xiàn)icon刷新轉(zhuǎn)動(dòng)效果,文章開頭給大家介紹了webkit-transform、animation、@keyframes這三個(gè)屬性,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一2025-02-19




