简单常用的幻灯片播放实现代码
2013-09-25 00:00
197 查看
幻灯片自动播放图片是当前网站比较流行的一个展示方式。在网上我们能找到各种特效丰富的幻灯片插件和代码。这里项目需要,我自己做了一个简单的,就不详细讲解了,代码很简单。直接看效果图和代码吧。
![](https://oscdn.geek-share.com/Uploads/Images/Content/2015/2015030182/279558f0be9fcddc258003eff65010f1)
所有代码 ppt.html,需要提供相应图片才能显示:
所有代码 ppt.html,需要提供相应图片才能显示:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <title>PPT Demo</title> <style type="text/css"> .ppt-container, .ppt-container ul, .ppt-container li, .ppt-container img { margin : 0; padding : 0; border : 0; } .ppt-container { width : 752px; /*根据展示图片的大小在这里设置容器的width和height*/ height : 328px; position : relative; } .ppt-container img { width : 100%; height : 100%; } .ppt-container .hide { display : none; } .ppt-container ul.image-list li { position : absolute; top : 0px; left : 0px; } .ppt-container ul.button-list { list-style : none; position : absolute; right : 20px; bottom : 20px; } .ppt-container ul.button-list li { float : left; padding-right : 10px; } .ppt-container ul.button-list span { background : #E5E5E5; padding : 1px 7px; line-height : 20px; font-size : 13px; display : block; cursor : default; } .ppt-container ul.button-list span.selected { color : #FFF; background : #FF7000; } </style> <script type="text/javascript"> $(function() { var iCountOfImage = 3; // 共三张图片 var iPreIndex = 0; // 上一次索引位置 $(".ppt-container ul.button-list li span").click(function() { var iIndex = $(this).attr("data-index"); if(iIndex == iPreIndex) { return; // 点击了当前图片,不切换 } $(".ppt-container .image-list li[data-index="+ iIndex +"]").fadeIn(1500); $(".ppt-container .image-list li[data-index="+ iPreIndex +"]").fadeOut(1500); iPreIndex = iIndex; $(".ppt-container .button-list span").removeClass("selected"); $(this).addClass("selected"); }); setInterval(function() { // 自动播放,每5秒触发一次单击事件,来播放幻灯片 var iNextIndex = (iPreIndex + 1) % iCountOfImage; $(".ppt-container ul.button-list li span[data-index="+ iNextIndex +"]").click(); }, 5000); }); </script> </head> <body> <div class="ppt-container"> <ul class="image-list"> <li data-index="0"><img src="ppt-images/ppt-1.jpg"/></li> <li data-index="1" class="hide"><img src="ppt-images/ppt-2.jpg"/></li> <li data-index="2" class="hide"><img src="ppt-images/ppt-3.jpg"/></li> </ul> <ul class="button-list"> <li><span data-index="0" class="selected">1</span></li> <li><span data-index="1">2</span></li> <li><span data-index="2">3</span></li> </ul> </div> </body> </html>
相关文章推荐
- C++临时对象
- jedi-vim python插件
- 【ZZ】python - __str__ 和 __repr__
- 【ZZ已解决】Python中如何在嵌套函数内部访问被嵌套(的父级函数)中的(局部,非全局)变量
- 【ZZ】python命名空间与作用域
- 【ZZ】python中的异常处理
- PHP nusoap返回UTF-8中文乱码的解决办法
- AOP: Spring3核心技术之AOP配置
- C#:System.Array简单使用
- java.lang.IllegalArgumentException : can't parse argument number MessageFormat
- Barcode Xpress如何在Visual C++中作为COM对象使用(2)
- 最实用的10个重构小技巧
- C语言打印圣诞树
- 5个让人激动的Java项目
- 统计过去数据一个php脚本
- SpringMVC整合Fastjason时出现中文乱码
- C#_delegate - 用委托实现事件,Display和Log类都使用Clock对象
- Java多线程程序设计
- java值传递
- 18款在线代码片段测试工具