Swiper实现带两侧带遮罩层的滑动效果
来源:互联网 发布:java开方运算式 编辑:程序博客网 时间:2024/05/22 08:04
swiper 3我原来采用的是swiper3实现的
主要代码我po一下
html:
<divclass="swiper-container">
<divclass="swiper-wrapper">
<divclass="swiper-slide swiper-slide-1">
<div>
<aclass="btn-disableQ">每天10:00</a>
<aclass="btn-ableQ">立即抢</a>
</div>
</div>
<divclass="swiper-slide swiper-slide-2">
<div>
<aclass="btn-disableQ">每天13:00</a>
<aclass="btn-ableQ">立即抢</a>
</div>
</div>
<divclass="swiper-slide swiper-slide-3">
<div>
<aclass="btn-disableQ">每天17:00</a>
<aclass="btn-ableQ">立即抢</a>
</div>
</div>
<divclass="swiper-slide swiper-slide-4">
<div>
<aclass="btn-disableQ">每天20:00</a>
<aclass="btn-ableQ">立即抢</a>
</div>
</div>
</div>
<divclass="swiper-button-prev"></div>
<divclass="swiper-button-next"></div>
</div>
css:
.swiper-container{
margin:0170px;
}
.swiper-slide{
width:558px;
}
.swiper-slidea{
transition:0.2s;
}
.swiper-pagination{
text-align:center;
width:100%;
margin-top:10px;}
.swiper-pagination.swiper-pagination-bullet{
width:12px;
height:12px;
margin:05px;
background:#02328d;
}
.swiper-button-prev{
width:32px;
height:92px;
background:url(../images/slide_prev.png)no-repeatcenterrgba(255,255,255,.8);
left:200px;
border-radius:5px;
}
.swiper-button-next{
width:32px;
height:92px;
background:url(../images/slide_after.png)no-repeatcenterrgba(255,255,255,.8);
right:200px;
border-radius:5px;
}
.swiper-button-prev:hover,.swiper-button-next:hover{
background-color:rgba(255,255,255,1);
}
.swiper-slide{
width:518px;
height:448px;
background:url(../images/qiangBg-1.png)no-repeatcenter;
}
.swiper-slide>div{
width:518px;
height:448px;
padding-top:334px;
background:url(../images/qiangBg-gray2.png)no-repeatcenter;
}
.swiper-slide.nobg>div{
background:none;
}
.swiper-slide-2{
background:url(../images/qiangBg-2.png)no-repeatcenter;
}
.swiper-slide-3{
background:url(../images/qiangBg-3.png)no-repeatcenter;
}
.swiper-slide-4{
background:url(../images/qiangBg-4.png)no-repeatcenter;
}
.qiang.box.innerimg{
width:310px;
display:block;
margin:0auto;
padding-top:143px;
}
.swiper-slidea{
cursor:pointer;
display:block;
font-size:34.25px;
width:309px;
margin:0auto;
height:66.5px;
line-height:66.5px;
-moz-border-radius:66.5px;
-webkit-border-radius:66.5px;
border-radius:66.5px;
text-align:center;
background-image:-webkit-linear-gradient(toleft,#fc8f4e,#f84b47);
background-image:linear-gradient(toleft,#fc8f4e,#f84b47);
-moz-box-shadow:01px5px0#f8e0e0;
-webkit-box-shadow:01px5px0#f8e0e0;
box-shadow:01px5px0#f8e0e0;
}
.swiper-slidea.btn-ableQ{
display:none;
}
.swiper-slidea.btn-disableQ{
background:#ccc;
-moz-box-shadow:none;
-webkit-box-shadow:none;
box-shadow:none;
}
js:
<script>
varswiper= newSwiper('.swiper-container',{
autoplay:3000,
loop:true,
loopedSlides:3,
spaceBetween:0,
centeredSlides:true,
slidesPerView:'auto',
nextButton:'.swiper-button-next',
prevButton:'.swiper-button-prev',
onSlideChangeStart:function(swiper){
$('.swiper-wrapper').find('.swiper-slide').eq(swiper.activeIndex).siblings().removeClass('nobg');
varas=$('.swiper-wrapper').find('.swiper-slide').eq(swiper.activeIndex).addClass('nobg')
},
});
</script>
但是swiper3存在兼容ie9的问题
因而改用了swiper 2实现这个
html:
<divclass="swiper-container">
<divclass="swiper-button-prev"></div>
<divclass="swiper-button-next"></div>
<divclass="swiper-wrapper">
<divclass="swiper-slide swiper-slide-1">
<div>
<aclass="btn-disableQ">每天10:00</a>
<aclass="btn-ableQ">立即抢</a>
</div>
</div>
<divclass="swiper-slide swiper-slide-2 nobg">
<div>
<aclass="btn-disableQ">每天13:00</a>
<aclass="btn-ableQ">立即抢</a>
</div>
</div>
<divclass="swiper-slide swiper-slide-3">
<div>
<aclass="btn-disableQ">每天17:00</a>
<aclass="btn-ableQ">立即抢</a>
</div>
</div>
<divclass="swiper-slide swiper-slide-4">
<div>
<aclass="btn-disableQ">每天20:00</a>
<aclass="btn-ableQ">立即抢</a>
</div>
</div>
</div>
</div>
css:
.swiper-container{
margin: 0 170px;
height: 448px;
}
.swiper-slide{
width:558px;
}
.swiper-slide a{
transition: 0.2s;
}
.swiper-pagination{
text-align:center;
width:100%;
margin-top:10px;}
.swiper-pagination .swiper-pagination-bullet {
width: 12px;
height: 12px;
margin:0 5px;
background:#02328d;
}
.swiper-button-prev{
width: 32px;
height: 92px;
background: url(../images/slide_prev.png) no-repeat center rgba(255,255,255,.8);
left: 200px;
border-radius: 5px;
position: absolute;
z-index: 2;
top: 50%;
margin-top: -46px;
cursor: pointer;
}
.swiper-button-next{
width: 32px;
height: 92px;
background: url(../images/slide_after.png) no-repeat center rgba(255,255,255,.8);
right: 200px;
border-radius: 5px;
position: absolute;
z-index: 2;
top: 50%;
margin-top: -46px;
cursor: pointer;
}
.swiper-button-prev:hover,.swiper-button-next:hover{
background-color: rgba(255,255,255,1);
}
.swiper-slide{
width: 518px;
height: 448px;
background: url(../images/qiangBg-1.png) no-repeat center;
}
.swiper-slide>div{
width: 100%;
height: 448px;
padding-top: 334px;
background: url(../images/qiangBg-gray2.png) no-repeat center;
}
.swiper-slide.nobg>div{
background: none;
}
.swiper-slide-2{
background: url(../images/qiangBg-2.png) no-repeat center;
}
.swiper-slide-3{
background: url(../images/qiangBg-3.png) no-repeat center;
}
.swiper-slide-4{
background: url(../images/qiangBg-4.png) no-repeat center;
}
.qiang .box .inner img{
width: 310px;
display: block;
margin: 0 auto;
padding-top: 143px;
}
.swiper-slide a{
cursor: pointer;
display: block;
font-size: 34.25px;
width: 309px;
margin: 0 auto;
height: 66.5px;
line-height: 66.5px;
-moz-border-radius: 66.5px;
-webkit-border-radius: 66.5px;
border-radius: 66.5px;
text-align: center;
background-image: -webkit-linear-gradient(to left, #fc8f4e, #f84b47);
background-image: linear-gradient(to left, #fc8f4e, #f84b47);
-moz-box-shadow: 0 1px 5px 0 #f8e0e0;
-webkit-box-shadow: 0 1px 5px 0 #f8e0e0;
box-shadow: 0 1px 5px 0 #f8e0e0;
}
.swiper-slide a.btn-ableQ{
display: none;
}
.swiper-slide a.btn-disableQ{
background: #ccc;
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}
js有稍许变化:
<script>
varswiper= newSwiper('.swiper-container',{
autoplay:3000,
slidesPerView:3,
loop:true,
loopAdditionalSlides:2,
autoplayDisableOnInteraction:false,
onSlideChangeStart:function(swiper){
$('.swiper-wrapper').find('.swiper-slide').eq(swiper.activeIndex).next().addClass('nobg')
$('.swiper-wrapper').find('.swiper-slide').eq(swiper.activeIndex).next().siblings().removeClass('nobg');
},
});
$('.swiper-button-prev').on('click',function(e){
e.preventDefault()
swiper.swipePrev()
})
$('.swiper-button-next').on('click',function(e){
e.preventDefault()
swiper.swipeNext()
})
</script>
效果还是如上图一样但是感觉要稍微卡顿一些的。
最后还是有问题及时兼容了Ie9了就是存在于切换完一轮以后对中间状态的判定谁应该是亮色的由于active状态的是第一张
然后用了没这么优雅的效果就是用aboslute给两边slide所占位出添加阴影块。
阅读全文
0 0
- Swiper实现带两侧带遮罩层的滑动效果
- h5用swiper结合angularjs实现手机浏览器左右滑动切换图片的效果
- 使用swiper插件实现qq聊天窗口按钮滑动效果
- swiper实现触摸滑动
- Javascript滑动效果利器--Swiper
- 使用swiper写的m站横向滑动效果
- Viewpager 实现画廊Gallery效果,左右两侧随着滑动一定比例缩放
- 出色的html滑动效果库 swiper -例子5 横向自由滑动 可以滑动部分
- swiper滑动实现幻灯片功能及swiper animate的动画特效
- 出色的html滑动效果库 swiper -例子4 超长单栏横向滑动
- 带滑动条的导航栏(中)---jQuery实现滑动效果
- 使用自定义RadioButton和ViewPager实现TabHost效果和带滑动的页卡效果。
- 利用swiper.js 实现 html5 模仿手指滑动切屏效果
- vue2.0引用vue-awesome-swiper插件实现左右滑动轮播效果
- 不错的滑动插件swiper
- Swiper实现图片滚动效果
- 【Swiper插件应用-01】基于Swiper实现的列表切换效果
- 屏幕滑动效果的实现
- 女人一生必须拥有的珍珠
- BurpSuite 学习使用教程
- Android 中LayoutInflater(布局加载器)之介绍篇
- 水经微图与万能地图下载器功能比较
- javawebday10补充(xpath内容总结)
- Swiper实现带两侧带遮罩层的滑动效果
- HW0
- 递归--汉诺塔
- Hopfield神经网络的通俗理解
- 网页实现鼠标拖拽div
- sql server 中止运行时间超过阈值的作业
- 第四章、ReactNative组件的封装
- VC与JavaScript交互(三) ———— JS调用C++
- 数据库连接池C3P0学习