查看: 1621|回复: 3
打印 上一主题 下一主题

【求助】第一次往右拖出现异常

[复制链接]
  • TA的每日心情
    开心
    2019-11-18 11:03
  • 签到天数: 1 天

    [LV.1]初来乍到

    1

    主题

    5

    帖子

    15

    积分

    新手上路

    Rank: 1

    积分
    15
    跳转到指定楼层
    楼主
    发表于 2019-11-18 11:02:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    往左拖动倒是正常。用的是 swiper-5.2.0。




    以下是代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <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 rel="stylesheet" href="css/swiper.css">
    <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-container {
            width: 750px;
            height: 300px;
            overflow:hidden;
            background-color:#00CCFF;
    }
    .swiper-slide,
    .swiper-slide-duplicate {
            text-align: center;
            font-size: 18px;
            background: #fff;
            border-radius: 20px;
            display: block;
            display: -webkit-box;
            display: -ms-flexbox;
            display: -webkit-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;
            transition: 300ms;
            margin-top:25px;
            width:525px;
            height:250px;
    }
    .swiper-slide-active,
    .swiper-slide-duplicate-active{
            margin-top:0px;
            width:630px;
            height:300px;
    }
    /*---页码---*/
    .swiper-pagination-bullet{
            width: 19px;
            height: 10px;
            background: url(images/banner_page1.png);
            border-radius: 0px;
            opacity:1;
    }
    .swiper-pagination-bullet-active{
            width: 38px;
            height: 10px;
            background: url(images/banner_page2.png);
    }

    </style>
    </head>
    <body>
    <div class="swiper-container">
            <div class="swiper-wrapper">
                    <img src="images/1.jpg" class="swiper-slide" />
                    <img src="images/2.jpg" class="swiper-slide" />
                    <img src="images/3.jpg" class="swiper-slide" />
            </div>
            <div class="swiper-pagination"></div>
    </div>
    <script src="js/swiper.js"></script>
    <script>
            var swiper = new Swiper('.swiper-container', {
                    slidesPerView: 'auto',  //容器中显示的图片数量
                    spaceBetween: 20,   //间隔
                    slidesOffsetBefore: -45,  //左偏移
                    loop: true,       //循环播放
                    //autoplay: true,   //自动播放
                    //delay: 3000,      //停留时间,毫秒
                    pagination: {
                    el: '.swiper-pagination',
                    clickable: true,
            },
            });
    </script>
    </body>
    </html>



    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏 分享分享 分享淘帖
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2019-11-18 11:03
  • 签到天数: 1 天

    [LV.1]初来乍到

    1

    主题

    5

    帖子

    15

    积分

    新手上路

    Rank: 1

    积分
    15
    沙发
     楼主| 发表于 2019-11-18 11:05:51 | 只看该作者
    代码打包:
    swiper.zip (316.46 KB, 下载次数: 0)


    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2019-11-18 11:03
  • 签到天数: 1 天

    [LV.1]初来乍到

    1

    主题

    5

    帖子

    15

    积分

    新手上路

    Rank: 1

    积分
    15
    板凳
     楼主| 发表于 2019-11-18 15:52:57 | 只看该作者
    自己解决了,代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <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 rel="stylesheet" href="css/swiper.css">
    <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-container {
            width: 750px;
            height: 300px;
            overflow:hidden;
            background-color:#00CCFF;
    }
    .swiper-slide {
            width:630px;
            height:300px;
            display: block;
            display: -webkit-box;
            display: -ms-flexbox;
            display: -webkit-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;
            transition: 300ms;
    }
    .swiper-slide img{
            border-radius: 20px;
            width:630px;
            height:300px;
    }
    .swiper-slide-active img,
    .swiper-slide-duplicate-active img{
    }
    .swiper-slide-prev img,
    .swiper-slide-next img{
            width:525px;
            height:250px;
    }
    .swiper-slide-prev img{
            margin-right:-90px;
    }
    .swiper-slide-next img{
            margin-left:-90px;
    }
    /*---页码---*/
    .swiper-pagination-bullet{
            width: 19px;
            height: 10px;
            background: url(images/banner_page1.png);
            border-radius: 0px;
            opacity:1;
    }
    .swiper-pagination-bullet-active{
            width: 38px;
            height: 10px;
            background: url(images/banner_page2.png);
    }

    </style>
    </head>
    <body>
    <div class="swiper-container">
            <div class="swiper-wrapper">
                    <div class="swiper-slide"><img src="images/1.jpg" /></div>
                    <div class="swiper-slide"><img src="images/2.jpg" /></div>
                    <div class="swiper-slide"><img src="images/3.jpg" /></div>
            </div>
            <div class="swiper-pagination"></div>
    </div>
    <script src="js/swiper.js"></script>
    <script>
            var swiper = new Swiper('.swiper-container', {
                    centeredSlides: true,   //居中
                    slidesPerView: 'auto',  //容器中显示的图片数量
                    spaceBetween: 20,   //图片间隔
                    loop: true,       //循环播放
                    //autoplay: true,   //自动播放
                    //delay: 3000,      //停留时间,毫秒
                    pagination: {
                    el: '.swiper-pagination',
                    clickable: true,
            },
            });
    </script>
    </body>
    </html>


    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2019-11-18 11:03
  • 签到天数: 1 天

    [LV.1]初来乍到

    1

    主题

    5

    帖子

    15

    积分

    新手上路

    Rank: 1

    积分
    15
    地板
     楼主| 发表于 2019-11-18 15:53:29 | 只看该作者
    感觉是用了  slidesOffsetBefore 这个参数的问题。
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Swiper中文网 ( 粤ICP备15001020号

    GMT+8, 2024-4-24 00:05 , Processed in 0.078917 second(s), 29 queries .

    Powered by Discuz! X3.2

    © 2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表