所有代码 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;
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>