简介
网易(163)的2014巴西世界杯主题页面做的算不错的,第一屏的幻灯片也很吸引眼球,今天我们就用 jQuery 幻灯片插件 Owl Carousel 制作一个类似的幻灯片。
兼容
浏览器兼容:兼容 IE6、IE7 及以上版本和其他主流浏览器,但效果并非所有浏览器一致。
制作方法
1、引入文件
<link rel="stylesheet" href="https://www.dowebok.com/css/owl.carousel.css" rel="external nofollow" > <script src="https://www.dowebok.com/js/jquery.min.js"></script> <script src="https://www.dowebok.com/js/owl.carousel.js"></script>
2、HTML
幻灯片的每一页都是一 ul 包含 4 个 li,下面只贴出第一页的代码,其他页仿照这依次写入即可。
<div id="owl-demo" class="owl-carousel"> <div class="itme"> <ul> <li class="li1"> <a href="https://www.dowebok.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="https://www.dowebok.com/img/a1.jpg" alt=""></a> <div class="txt"> <h3><a href="" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >阿根廷备战 队友倒地引梅西大笑</a></h3> <p>北京时间6月13日,阿根廷队训练备战,众将心情轻松,训练中,队友摔倒引梅西大笑。</p> </div> </li> <li class="li2"> <a href="https://www.dowebok.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="https://www.dowebok.com/img/b1.jpg" alt=""></a> <div class="txt"> <h3><a href="" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >葡萄牙备战 C罗情绪激动对队友指手画脚</a></h3> </div> </li> <li class="li3"> <a href="https://www.dowebok.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="https://www.dowebok.com/img/c1.jpg" alt=""></a> <div class="txt"> <h3><a href="" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >鲁尼投入训练不敢怠慢</a></h3> </div> </li> <li class="li3"> <a href="https://www.dowebok.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="https://www.dowebok.com/img/c2.jpg" alt=""></a> <div class="txt"> <h3><a href="" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >巴神备战炫酷墨镜拉风</a></h3> </div> </li> </ul> </div> </div>
3、CSS
CSS 代码仅贴出缩略图部分,更多代码请查看演示页面源代码或下载查看。
.owl-pagination { position: absolute; left: 0; bottom: 0; width: 100%; height: 80px; text-align: center; } .owl-page { position: relative; display: inline-block; width: 45px; height: 45px; margin: 0 5px; border-radius: 80px; *background-image: url(images/bg15.png); *display: inline; *zoom: 1; vertical-align: middle; overflow: hidden; } .owl-page img { width: 100%; height: 100%; border-radius: 80px; } .owl-pagination .active { width: 80px; height: 80px; } .owl-pagination span { position: absolute; left: 0; top: 0; width: 45px; height: 45px; *background-image: url(images/ico_clip_s.png); _background-image: none; } .owl-pagination .active span { width: 80px; height: 80px; background-image: url(images/ico_clip.png); _background-image: none; }
圆形缩略图的实现方式是:高级浏览器使用 CSS3 border-radius 属性;IE7、IE8 使用一个中间圆形透明的 png 图片盖在缩略图上面。
4、JavaScript
$(function(){ $('#owl-demo').owlCarousel({ items: 1, navigation: true, navigationText: ["上一个","下一个"], autoPlay: true, stopOnHover: true, afterInit: function(){ var $t = $('.owl-pagination span'); $t.each(function(i){ $(this).before('<img src="https://www.dowebok.com/img/t' + (i+1) + '.jpg">'); }) } }); });
Owl Carousel 本身并不支持缩略图,这里是通过 afterInit 回调函数插入到页面上的。
[b2_file link="
百度网盘" name="制作网易2014巴西世界杯专题幻灯片" pass="" code=""]