简单常用的幻灯片播放实现代码

(编辑:jimmy 日期: 2024/10/10 浏览:2)

幻灯片自动播放图片是当前网站比较流行的一个展示方式。在网上我们能找到各种特效丰富的幻灯片插件和代码。这里项目需要,我自己做了一个简单的,就不详细讲解了,代码很简单。直接看效果图和代码吧。
简单常用的幻灯片播放实现代码 
所有代码 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="/UploadFiles/2021-04-02/jquery.js"><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="/UploadFiles/2021-04-02/ppt-1.jpg"><li data-index="1" class="hide"><img src="ppt-images/ppt-2.jpg"><li data-index="2" class="hide"><img src="/UploadFiles/2021-04-02/ppt-3.jpg"></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>

一句话新闻

高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。