![[代码样式]用FlexSlider制作《枪神纪》幻灯片效果 [代码样式]用FlexSlider制作《枪神纪》幻灯片效果](https://www.weimahe.com/wp-content/uploads/2020/08/9sSo711545.jpg)
简介
这是模仿《枪神纪》官网首页的幻灯片,左边是图片,右边是标题导航。效果几乎一直,区别的是切换方式不一样,《枪神纪》官网的是鼠标移动到上面切换,模仿的是鼠标点击切换。因为这个幻灯片是使用 FlexSlider 制作的,而 FlexSlider 没有参数设置事件方式。
兼容性
兼容所有主流浏览器,包括 IE6。
制作方法
1、引入文件
<script src="https://www.dowebok.com/js/jquery.min.js"></script> <script src="https://www.dowebok.com/js/jquery.flexslider-min.js"></script>
2、HTML
<div class="slide-bar"> <ul class="slides"> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="https://www.dowebok.com/images/img1.jpg" alt="img1"></a> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="https://www.dowebok.com/images/img2.jpg" alt="img2"></a> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="https://www.dowebok.com/images/img3.jpg" alt="img3"></a> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="https://www.dowebok.com/images/img4.jpg" alt="img4"></a> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="https://www.dowebok.com/images/img5.jpg" alt="img4"></a> </ul> <ul class="slide-caption"> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >最难忘的圣诞礼物 <span class="new">N</span></a></li> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >百万Q币悬赏最强特工 <span class="hot">H</span></a></li> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >挑战模式预告专题</a></li> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >郭敬明新书免费看</a></li> <li><a href="###" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >《艺术生存》上线</a></li> </ul> </div>
如果你了解 FlexSlider 的话,就知道 FlexSlider 默认的 HTML 是没有 <ul class="slide-caption"> 的,我们这里加入是用来做自定义导航,就是右边的标题导航。
3、CSS
* { margin: 0; padding: 0;}
.slide-bar { position: relative; width: 550px; height: 230px; padding-right: 230px; margin: 0 auto; overflow: hidden;}
.slides img { display: block;}
.slide-caption { position: absolute; right: 0; top: 0; width: 230px; background-color: #0F1E26;}
.slide-caption li, .slide-caption a { display: block; width: 230px; height: 45px; border-bottom: 1px solid #1a2c34}
.slide-caption a { font: 14px/45px "Microsoft Yahei"; color: #a8a8a8; text-align: center; text-decoration: none; box-shadow: 5px -5px 18px #002436 inset;}
.slide-caption .flex-active a { color: #fff; background-color: #005278;}
.slide-caption .new { display: inline-block; width: 11px; height: 11px; font: 8px/11px "Microsoft Yahei"; background-color: #7fd416; color: #eee; vertical-align: text-top;}
.slide-caption .hot { display: inline-block; width: 11px; height: 11px; font: 8px/11px "Microsoft Yahei"; background-color: #da3434; color: #eee; vertical-align: text-top;}
4、JavaScript
$(window).load(function() {
$('.slide-bar').flexslider({
'animation' : 'slide',
'direction' : 'vertical',
'pauseOnHover' : true,
'directionNav' : false,
'manualControls' : '.slide-caption li'
});
});
