简单常用的幻灯片播放实现代码
幻灯片自动播放图片是当前网站比较流行的一个展示方式。在网上我们能找到各种特效丰富的幻灯片插件和代码。这里项目需要,我自己做了一个简单的,就不详细讲解了,代码很简单。直接看效果图和代码吧。
所有代码 ppt.html,需要提供相应图片才能显示:
PPT Demo.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;
}
$(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);
});
相关阅读:
jQuery子窗体取得父窗体元素的方法
Android创建文件实现对文件监听示例
js微信分享API
C++中指针的数据类型和运算相关知识小结
JQuery实现图片轮播效果
兼容主流浏览器的JS复制内容到剪贴板
apply和call方法定义及apply和call方法的区别
win7系统创建系统映像的详细教程
ASP.NET中MVC使用AJAX调用JsonResult方法并返回自定义错误信息
Android软键盘弹出时的界面控制方法
Java各种排序算法汇总(冒泡,选择,归并,希尔及堆排序等)
纯CSS3实现带动画效果导航菜单无需js
Win8.1系统自带的“定位设置”功能怎么使用?
sqlserverdriver配置方法 jdbc连接sqlserver