本文主要是介绍使用jq和css3自制图片滚轮,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
效果展示
这边做的层次感不是很明显,可以自己调节css
目标效果
- 左右按钮控制图片左右切换
- 备注信息从下往上缓慢滑出
思路
- 信息滑出很简单,用css3做就行
- 左右控制图片,使用定位做,给五个图片分别定位,命名5个class,当右切换,最左边的class切换成默认left,然后从左至右从新给予定义好的五个class
做法
- 信息从下往上滑出
/*info应该被包裹在box里*/
.box{position: relative;
}.box .info{position: absolute;left: 0;bottom: 0;transition: height 0.6s;width: 100%;height: 0;
}.box:hover > .info{height: auto; /*或者其他定高*/
}
- 切换图片
切换前new img定位和right-2同样位置,但是z-index比right-2低,隐藏在他下面
切换后的默认样式也是,定位在left-1下面
js
$(".turn-right").click(function(){if($(".main").next().prop('class') === undefined){return false;}$(".left-1").prop('class','match-item left');$(".left-2").prop('class','match-item left-1');$(".main").prop('class','match-item left-2');$(".right-1").prop('class','match-item main');var right = $(".right-2");right.prop('class','match-item right-1');right.next().prop('class','match-item right-2');
});$(".turn-left").click(function(){if($(".main").prev().prop('class') === undefined){return false;}$(".right-2").prop('class','match-item right');$(".right-1").prop('class','match-item right-2');$(".main").prop('class','match-item right-1');$(".left-2").prop('class','match-item main');var left = $(".left-1");left.prop('class','match-item left-2');left.prev().prop('class','match-item left-1');
});
html
<div class="slide"><div class="turn-left"><span class="arrow-left"></span></div><ul class="match-list pst"><li class="match-item left-1"><img src="1.png" alt="" width="100%" /><div class="info"><p>球场:<span class="color-blue">成都观岭</span></p><p>一杆进洞奖金:<span class="color-yellow">2000元</span></p><p>2017.05.01~2017.05.31</p></div></li><li class="match-item left-2"><img src="2.png" alt="" width="100%" /><div class="info"><p>球场:<span class="color-blue">成都观岭</span></p><p>一杆进洞奖金:<span class="color-yellow">2000元</span></p><p>2017.05.01~2017.05.31</p></div></li><li class="match-item main"><img src="3.png" alt="" width="100%" /><div class="info"><p>球场:<span class="color-blue">成都观岭</span></p><p>一杆进洞奖金:<span class="color-yellow">2000元</span></p><p>2017.05.01~2017.05.31</p></div></li><li class="match-item right-1"><img src="1.png" alt="" width="100%" /><div class="info"><p>球场:<span class="color-blue">成都观岭</span></p><p>一杆进洞奖金:<span class="color-yellow">2000元</span></p><p>2017.05.01~2017.05.31</p></div></li><li class="match-item right-2"><img src="2.png" alt="" width="100%" /><div class="info"><p>球场:<span class="color-blue">成都观岭</span></p><p>一杆进洞奖金:<span class="color-yellow">2000元</span></p><p>2017.05.01~2017.05.31</p></div></li><li class="match-item"><img src="3.png" alt="" width="100%" /><div class="info"><p>球场:<span class="color-blue">成都观岭</span></p><p>一杆进洞奖金:<span class="color-yellow">2000元</span></p><p>2017.05.01~2017.05.31</p></div></li></ul><div class="turn-right"><span class="arrow-right"></span></div><div class="clearfix"></div>
</div>
css
.match .turn-left,.match .turn-right{display: inline-block;vertical-align: middle;width: 80px;height: 400px;cursor: pointer;margin: 0 20px;
}.match .turn-left:hover{background: linear-gradient(to left,rgba(96,110,122,0.8),rgba(96,110,122,0));
}.match .turn-right:hover{background: linear-gradient(to right,rgba(96,110,122,0.8),rgba(96,110,122,0));
}.match .turn-left .arrow-left,.match .turn-right .arrow-right{position: relative;
}.match .turn-left .arrow-left:before{content: '';display: inline-block;width: 50px;height: 10px;transform: skewY(-45deg);background-color: #eee;position: absolute;top: 150px;left: 15px;
}.match .turn-left .arrow-left:after{content: '';display: inline-block;width: 50px;height: 10px;transform: skewY(45deg);background-color: #eee;position: absolute;top: 200px;left: 15px;
}.match .turn-right .arrow-right:before{content: '';display: inline-block;width: 50px;height: 10px;transform: skewY(45deg);background-color: #eee;position: absolute;top: 150px;left: 15px;
}.match .turn-right .arrow-right:after{content: '';display: inline-block;width: 50px;height: 10px;transform: skewY(-45deg);background-color: #eee;position: absolute;top: 200px;left: 15px;
}.match .match-list{width: 800px;height: 405px;padding: 20px 0;vertical-align: middle;display: inline-block;white-space: nowrap;overflow-x: hidden;overflow-y: hidden;position: relative;
}.match .match-item{z-index: 100;position: absolute;top: 72px;left: 550px;width: 200px;height: 300px;display: inline-block;margin: 0 10px 10px;box-shadow: 0 1px 8px 2px rgba(1,1,1,0.8);border-radius: 2px;transition: all 1s;cursor: pointer;vertical-align: middle;
}.match .match-item:hover{transform: scale(1.05);box-shadow: 0 1px 10px 4px rgba(1,1,1,0.8);
}.match .left-1{z-index: 300 !important;position: absolute;top: 72px;left: 10px;width: 200px;height: 300px;
}.match .left-2{z-index: 400 !important;position: absolute;top: 35px;left: 145px;width: 250px;height: 375px;
}.match .main{z-index: 500 !important;position: absolute;top: 20px;left: 280px;width: 270px;height: 405px;
}.match .right-1{z-index: 400 !important;position: absolute;top: 35px;left: 415px;width: 250px;height: 375px;
}.match .right-2{z-index: 300 !important;position: absolute;top: 72px;left: 550px;width: 200px;height: 300px;
}.match .left{z-index: 100;position: absolute;top: 72px;left: 10px;width: 200px;height: 300px;
}.match .right{z-index: 100;position: absolute;top: 72px;left: 550px;width: 200px;height: 300px;
}.match .info{position: absolute;left: 0;bottom: 0;width: 100%;height: 0;overflow: hidden;padding: 0;z-index: 200;transition: all 1s;background-color: rgba(0,0,0,0.6);
}.match .main .info{height: 120px;
}.match .info p{font-size: 16px;font-family: SourceHanSansCN-Medium, sans-serif;color: #f0f0f0;margin: 5px 10px;padding: 0;line-height: 30px;height: 30px;text-shadow: 1px 1px rgba(1,1,1,0.6);
}.match .info .color-blue{color: #00a1fe;font-size: 18px;
}.match .info .color-yellow{color: #e07e3e;font-size: 18px;
}
这篇关于使用jq和css3自制图片滚轮的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!