简介
《英雄联盟》是腾讯游戏代理运营的英雄对战 MOBA 竞技网游,该游戏目前非常火爆。这次我们使用 jQuery 幻灯片插件 FlexSlider 制作《英雄联盟》官网的幻灯片。
浏览器兼容
IE6+ | Edge | Chrome | Firefox | Opera | Safari |
制作方法
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="dowebok"> <ul class="slides"> <li><a href="https://www.dowebok.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank"><img src="https://www.dowebok.com/images/1.jpg" alt=""></a></li> <li><a href="https://www.dowebok.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank"><img src="https://www.dowebok.com/images/2.jpg" alt=""></a></li> <li><a href="https://www.dowebok.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank"><img src="https://www.dowebok.com/images/3.jpg" alt=""></a></li> <li><a href="https://www.dowebok.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank"><img src="https://www.dowebok.com/images/4.jpg" alt=""></a></li> <li><a href="https://www.dowebok.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank"><img src="https://www.dowebok.com/images/5.jpg" alt=""></a></li> </ul> <ul class="slide-caption"> <li><a href="https://www.dowebok.com/javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >欧米伽小队售卖</a></li> <li><a href="https://www.dowebok.com/javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >武器大师竞技场</a></li> <li><a href="https://www.dowebok.com/javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >凯隐连招教学全解密</a></li> <li><a href="https://www.dowebok.com/javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >《凡性的提醒》</a></li> <li><a href="https://www.dowebok.com/javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >深度复盘第61期</a></li> </ul> </div>
FlexSlider 默认的 HTML 是没有 <ul class="slide-caption">
,这里加入用来做自定义导航。
3、CSS
* { margin: 0; padding: 0;} .dowebok { position: relative; width: 820px; height: 347px; margin: 0 auto; padding-bottom: 50px; overflow: hidden; background-color: #f00;} .slides img { width: 100%; vertical-align: top;} .slide-caption { position: absolute; left: 0; bottom: 0; font-size: 0; background-color: #121212;} .slide-caption li, .slide-caption a { display: inline-block; width: 164px; height: 50px;} .slide-caption a { font: 14px/50px "Microsoft Yahei"; color: #c8c8c8; text-align: center; text-decoration: none;} .slide-caption .flex-active a { color: #e9c06c; background-color: #303030;}
4、JavaScript
$(window).load(function() { $('.dowebok').flexslider({ animation: 'slide', pauseOnHover: true, directionNav: false, manualControls: '.slide-caption li' }); });
《英雄联盟》官网幻灯片的切换方式是鼠标移入切换,而 FlexSlider 没有这样的参数设置,我们让鼠标移入出发点击事件,以此来实现这样的效果。在上面 JavaScript 代码后面加入一下代码:
var $item = $('.slide-caption').find('li'); $item.each(function(i) { var $this = $(this); $this.on('mouseenter', function() { $this.trigger('click'); }); });
[b2_file link="
百度网盘" name="FlexSlider制作《英雄联盟》幻灯片" pass="" code=""]