最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用swiper自定義分頁點擊跳轉指定頁面

 更新時間:2023年04月13日 10:36:26   作者:你看我像是會的樣子嗎?  
這篇文章主要介紹了使用swiper自定義分頁點擊跳轉指定頁面方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

swiper自定義分頁點擊跳轉指定頁面

mySwiper.slideTo(index, speed, runCallbacks),控制Swiper切換到指定slide。

參數名類型是否必填描述
indexnum必選指定將要切換到的slide的索引
speednum可選切換速度(單位ms)
runCallbacksboolean可選設置為false時不會觸發(fā)transition回調函數

(更多方法見Swiper官網)

效果圖如下:

<!--banner開始-->
<div class="banner">
    <div class="swiper-container">
        <div class="swiper-wrapper">
            <div class="swiper-slide">
                <img src="Static/Images/banner_1.jpg" alt="banner">
            </div>
            <div class="swiper-slide">
                <img src="Static/Images/banner_1.jpg" alt="banner">
            </div>
        </div>
        <div class="swiper-button-prev"></div><!--左箭頭。如果放置在swiper-container外面,需要自定義樣式。-->
        <div class="swiper-button-next"></div><!--右箭頭。如果放置在swiper-container外面,需要自定義樣式。-->
        <!--分頁器 -->
        <div class="swiper-pagination"></div>
    </div>
</div>
<script>
    var mySwiper = new Swiper('.swiper-container', {
        autoplay: true,//可選選項,自動滑動
        loop: true, // 循環(huán)模式選項,true 循環(huán)播放
        observer: true,//實時檢測,動態(tài)更新
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },//前進后退箭頭
        pagination: {//自定義分頁
            el: '.swiper-pagination',
            type: 'custom',
            autoplayDisableOnInteraction: false,
            renderCustom: function (swiper, current, total) {
                var paginationHtml = " ";
                for (var i = 0; i < total; i++) {
                    // 判斷是不是激活焦點,是的話添加active類,不是就只添加基本樣式類
                    if (i === (current - 1)) {
                        paginationHtml += '<span class="swiper-pagination-customs swiper-pagination-customs-active"><p class="swiper-pagination-li"></p></span>';
                    } else {
                        paginationHtml += '<span class="swiper-pagination-customs"><p class="swiper-pagination-li"></p></span>';
                    }
                }
                return paginationHtml;
            },
        },
    });
    $('.swiper-pagination').on('click','span',function(){
        var index = $(this).index()+1 ;
        mySwiper.slideTo(index, 1000, false)//切換到對應的slide,速度為1秒

    });


</script>
<!--banner結束-->

/*banner*/
.banner {
    position: relative;
}

.swiper-container {
    margin-left: auto;
    margin-right: auto;
    position: relative;
    overflow: hidden;
    list-style: none;
    padding: 0;
    z-index: 1;
}

.swiper-button-next, .swiper-button-prev {
    position: absolute;
    top: 50%;
    width: 32px;
    height: 32px;
    margin-top: -22px;
    z-index: 10;
    cursor: pointer;
    -moz-background-size: 27px 44px;
    -webkit-background-size: 27px 44px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat
}

.swiper-button-next {
    background-image: url("../Images/banner_right.png");
    right: 10px;

}

.swiper-button-prev {
    background-image: url("../Images/banner_left.png");
    left: 10px;
}

.swiper-button-next.swiper-button-disabled, .swiper-button-prev.swiper-button-disabled {
    opacity: .35;
    cursor: auto;
    pointer-events: none
}

.swiper-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: flex;
    transition-property: transform;
    box-sizing: content-box
}

.swiper-slide {
    flex-shrink: 0;
    width: 100%;
    height: 100%;
    position: relative;
    transition-property: transform
}

.swiper-slide img {
    width: 100%;
}

.swiper-pagination {
    position: absolute;
    text-align: center;
    transition: .3s opacity;
    transform: translate3d(0, 0, 0);
    z-index: 10
}

.swiper-pagination-custom {
    bottom: 12%;
    left: 0;
    width: 100%;
    height: 20px;
    text-align: center;
}

.swiper-pagination-li {
    width: 6px;
    height: 6px;
    background-color: #fff;
    position: absolute;
    top: 6px;
    left: 6px;
    border-radius: 50%;
}

.swiper-pagination-customs {
    width: 18px;
    height: 18px;
    display: inline-block;
    cursor: pointer;
    background: none;
    opacity: 1;
    border-radius: 50%;
    margin: 0 5px;
    outline: 0;
    position: relative;
}

.swiper-pagination-customs-active {
    opacity: 1;
    border: 1px solid #fff;
    background: none;
}

.banner-container {
    position: absolute;
    z-index: 999;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 50%;
    text-align: center;
    color: #fff;
}

.banner-container img {
    width: 80px;
    height: auto;
    display: table-cell;
    margin: 0 auto;
}

.banner-container .big-title {
    font-size: 44px;
    text-transform: uppercase;
    font-weight: 700;
    margin-top: 16px;
}

.banner-container .small-title {
    font-size: 20px;
    letter-spacing: 5px;
    margin: 14px 0;
}

.banner-btn {
    display: flex;
    justify-content: space-around;
    width: 45%;
    margin: 0 auto;
    margin-top: 30px;
}

.banner-btn .btn {
    width: 120px;
    height: 36px;
    border: 1px solid #fff;
    line-height: 36px;
    border-radius: 36px;
    font-size: 14px;
    transition: all 0.5s;
}

.banner-btn .btn:hover {
    width: 120px;
    height: 36px;
    border: 1px solid #fff;
    line-height: 36px;
    border-radius: 36px;
    font-size: 14px;
    color: #000000;
    background: #fff;
    font-weight: 600;
    cursor: pointer;
}

/*banner*/

swiper自定義分頁器

html部分

<div class="swiper-container">
? ? ?<div class="swiper-wrapper">
? ? ? ? <div class="swiper-slide">
? ? ? ? ? ? <img src="">
? ? ? ? </div>
? ? ?</div>
? ? ?<!-- 如果需要分頁器 -->
? ? ?<div class="swiper-pagination"></div>
</div>

js部分

<script type="text/javascript" src="js/swiper-bundle.min.js"> </script>
?
var mySwiper = new Swiper(".swiper-container", {
? ? pagination: {
? ? ? ? el: '.swiper-pagination',
? ? ? ? clickable: true,
? ? ? ? type:'custom', ? //自定義分頁器
? ? ? ? renderCustom: function (swiper, current, total) { ?
? ? ? ? ? ? var paginationHtml = " ";
? ? ? ? ? ? for (var i = 0; i < total; i++) {
? ? ? ? ? ? ? ? ?// 判斷是不是激活焦點,是的話添加active類,不是就只添加基本樣式類
? ? ? ? ? ? ? ? ?if (i === (current - 1)) {
? ? ? ? ? ? ? ? ? ? ? paginationHtml += '<span class="swiper-pagination-customs swiper-pagination-customs-active" ></span>'; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ?paginationHtml += '<span class="swiper-pagination-customs" ></span>';
? ? ? ? ? ? ? ? }?? ??? ??? ??? ??? ? ?
? ? ? ? ? ? }
? ? ? ? ? ? return paginationHtml;
? ? ? ? },
? ? }
});
? ? ? ? ? ? ? ? ? ?
//點擊分頁器跳轉到對應頁面
$(".swiper-pagination").on("click","span",function(){
? ? ? ? var index = $(this).index();
? ? ? ? mySwiper.slideTo(index);
})

css部分

.swiper-pagination-custom {
? ? height: 34px;
? ? text-align: end !important; ?//這里設置分頁器的位置 放在行的末尾
}
/*自定義分頁器的樣式*/
.swiper-pagination-customs {
? ? width: 34px;
? ? height: 34px;
? ? display:inline-block;
? ? border-radius: 5px;
? ? margin: 0 3px;
? ? outline: 0;
? ? box-sizing: border-box;
}
.swiper-pagination-customs:last-child{
? ? margin-right: 16px;
}
/*自定義分頁器激活時的樣式表現(xiàn)*/
.swiper-pagination-customs-active {
? ? border: 2px solid #fcb916;
? ? width: 36px;
? ? height: 36px;
}

解決動態(tài)加載數據滑動失效的問題

1. 在swiper初始化加兩行代碼

var mySwiper = new Swiper('.swiper-container', {?
?
?observer:true,//修改swiper自己或子元素時,自動初始化swiper?
?observeParents:true//修改swiper的父元素時,自動初始化swiper?
?
});

2.在數據請求后初始化swiper

function getMess(){
? ? globalParams = {
? ? ? ? //發(fā)送請求的參數
? ? }
? ? api.post2("xxx/xxx/xxx", globalParams, function(res) { ?//ajax請求
? ? ? ? var list = res.data.list;
? ? ? ? list.forEach((item) => {
? ? ? ? ? ? ? ? var itm = item.formModel.cgformFieldList
? ? ? ? ? ? ? ? var imgMess = itm[10].propertyLabel.split(",")
? ? ? ? ? ? ? ? var msg = "" ? ? ?// 輪播詳情
? ? ? ? ? ? ? ? imgMess.forEach((item) => {
? ? ? ? ? ? ? ? ? ? msg += `
? ? ? ? ? ? ? ? ? ? ? ? <div class="swiper-slide">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <img src="https://qiniu.hollysmart.com.cn/${item}">
? ? ? ? ? ? ? ? ? ? ? ? </div>`
? ? ? ? ? ? ? ? ? ? $(".swiper-wrapper").html(msg);//動態(tài)加載輪播項
?
? ? ? ? ? ? ? ? ? ? ? //初始化輪播組件
? ? ? ? ? ? ? ? ? ? var mySwiper = new Swiper(".swiper-container", {
? ? ? ? ? ? ? ? ? ? ? ? pagination: {
? ? ? ? ? ? ? ? ? ? ? ? ? ? el: '.swiper-pagination',
? ? ? ? ? ? ? ? ? ? ? ? ? ? clickable: true,
? ? ? ? ? ? ? ? ? ? ? ? ? ? type:'custom',
? ? ? ? ? ? ? ? ? ? ? ? ? ? renderCustom: function (swiper, current, total) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var paginationHtml = " ";
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for (var i = 0; i < total; i++) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 判斷是不是激活焦點,是的話添加active類,不是就只添加基本樣式類
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //要求是分頁器為縮小的輪播圖片 將圖片插入到元素中
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (i === (current - 1)) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? paginationHtml +=?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '<span class="swiper-pagination-customs swiper-pagination-customs-active" >' + `<img src="https://xxx.com.cn/${imgMess[i]}">` + '</span>';
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? paginationHtml += '<span class="swiper-pagination-customs" >'+ ?`<img src="https://xxx.com.cn/${imgMess[i]}">` +'</span>';
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }?? ??? ??? ??? ??? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return paginationHtml;
? ? ? ? ? ? ? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? //點擊分頁器跳轉到對應頁面
? ? ? ? ? ? ? ? ? ? $(".swiper-pagination").on("click","span",function(){
? ? ? ? ? ? ? ? ? ? ? ? var index = $(this).index();
? ? ? ? ? ? ? ? ? ? ? ? mySwiper.slideTo(index);
? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? })
? ? ? ? })
? ? })
}

記錄下jquery的使用方法 ,方便后續(xù)的查看

之后運用到vue時再繼續(xù)寫

總結

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • 學習Javascript面向對象編程之封裝

    學習Javascript面向對象編程之封裝

    這篇文章主要幫助大家學習Javascript面向對象編程之封裝,由淺入深的介紹了封裝的概念定義,感興趣的小伙伴們可以參考一下
    2016-02-02
  • 原生JS實現(xiàn)圖片輪播效果

    原生JS實現(xiàn)圖片輪播效果

    這篇文章主要為大家詳細介紹了原生JS實現(xiàn)圖片輪播效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • ES6概念 Symbol.keyFor()方法

    ES6概念 Symbol.keyFor()方法

    這篇文章主要介紹了ES6概念 Symbol.keyFor()方法 ,需要的朋友可以參考下
    2016-12-12
  • Javascript實現(xiàn)的Map集合工具類完整實例

    Javascript實現(xiàn)的Map集合工具類完整實例

    這篇文章主要介紹了Javascript實現(xiàn)的Map集合工具類,以完整實例形式分析了javascript實現(xiàn)map集合的構造、查找、刪除、判斷等相關技巧,需要的朋友可以參考下
    2015-07-07
  • JavaScript字符串處理常見操作方法小結

    JavaScript字符串處理常見操作方法小結

    這篇文章主要介紹了JavaScript字符串處理常見操作方法,結合實例形式分析了JavaScript字符串操作常見的轉換、截取、分割、獲取等相關實現(xiàn)技巧,需要的朋友可以參考下
    2019-11-11
  • 前端echarts加標記點及標記線和提示框詳細代碼示例

    前端echarts加標記點及標記線和提示框詳細代碼示例

    ECharts中的標記線是一條平行于x軸的水平線,有最大值、最小值、平均值等數據的標記線,它也是在series字段下進行配置的,下面這篇文章主要給大家介紹了關于前端echarts加標記點及標記線和提示框的相關資料,需要的朋友可以參考下
    2024-06-06
  • 使用JS給靜態(tài)頁面添加搜索功能的實現(xiàn)方法

    使用JS給靜態(tài)頁面添加搜索功能的實現(xiàn)方法

    靜態(tài)頁面通常由HTML、CSS 和 JavaScript 等靜態(tài)文件組成,這些文件在服務器上不會動態(tài)生成或修改,所以加載速度通常比較快,本文給大家介紹了如何只使用JS給靜態(tài)網頁添加站內全局搜索功能,文中有詳細的解決方案,需要的朋友可以參考下
    2023-11-11
  • 深入淺析js原型鏈和vue構造函數

    深入淺析js原型鏈和vue構造函數

    這篇文章主要介紹了js原型鏈和vue構造函數的相關知識,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2018-10-10
  • javascript 特殊字符串

    javascript 特殊字符串

    js字符串中出現(xiàn)任何< >標簽都可以,就是不能出現(xiàn)</script>標簽。
    2009-02-02
  • javascript 實現(xiàn)文本使用省略號替代(超出固定高度的情況)

    javascript 實現(xiàn)文本使用省略號替代(超出固定高度的情況)

    這篇文章主要介紹了javascript 實現(xiàn)文本使用省略號替代(超出固定高度的情況)的相關資料,需要的朋友可以參考下
    2017-02-02

最新評論

大竹县| 苍南县| 桦甸市| 波密县| 东丽区| 伊吾县| 土默特右旗| 扎赉特旗| 涡阳县| 三台县| 秭归县| 常山县| 安泽县| 罗江县| 宁国市| 柏乡县| 甘孜县| 吉安市| 连山| 兰州市| 贡觉县| 东阿县| 镇康县| 高要市| 工布江达县| 资源县| 丹巴县| 香港| 永定县| 麻江县| 唐海县| 贵溪市| 习水县| 贵州省| 徐水县| 武邑县| 达拉特旗| 海宁市| 瓦房店市| 洞口县| 应城市|