Swiper中文论坛

标题: 【求助】第一次往右拖出现异常 [打印本页]

作者: sosovipp    时间: 2019-11-18 11:02
标题: 【求助】第一次往右拖出现异常
往左拖动倒是正常。用的是 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>




作者: sosovipp    时间: 2019-11-18 11:05
代码打包:
swiper.zip (316.46 KB, 下载次数: 0)



作者: sosovipp    时间: 2019-11-18 15:52
自己解决了,代码:

<!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>



作者: sosovipp    时间: 2019-11-18 15:53
感觉是用了  slidesOffsetBefore 这个参数的问题。




欢迎光临 Swiper中文论坛 (http://bbs.swiper.com.cn/) Powered by Discuz! X3.2