js换图片效果可进行定时操作

 更新时间:2014年06月09日 17:55:54   作者:  
换图片效果想必大家都有见到过吧,但是定时换图片,貌似就很少见了,下面本文通过一个示例为大家详细介绍下
复制代码 代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'tu.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}
li {
list-style: none;
}
img {
border: 0;
}
a {
text-decoration: none;
}
#slide {
width: 800px;
height: 400px;
box-shadow: 0px 0px 5px #c1c1c1;
margin: 20px auto;
position: relative;
overflow: hidden;
}
#slide ul {
position: absolute;
left: 0px;
top: 0px;
height: 400px;
width: 11930px;
}
#slide ul li {
width: 800px;
height: 400px;
overflow: hidden;
float: left;
}
#slide .ico {
width: 800px;
height: 20px;
overflow: hidden;
text-align: center;
position: absolute;
left: 0px;
bottom: 10px;
z-index: 1;
}
#slide .ico a {
display: inline-block;
width: 10px;
height:10px;
background: url(out.png) no-repeat 0px 0px;
margin: 0px 5px;
}
#slide .ico .active {
background: url(out1.png) no-repeat 0px 0px;
}
#btnLeft {
width: 60px;
height: 400px;
left: 0px;
top: 0px;
background: url() no-repeat 0px 0px;
position: absolute;
z-index: 2;
}
#btnLeft :hover {
background: url() no-repeat 0px 0px;
}
#btnRight {
width: 60px;
height: 400px;
right: 0px;
top: 0px;
background: url() no-repeat 0px 0px;
position: absolute;
z-index: 2;
}
#btnRight :hover {
background: url() no-repeat 0px 0px;
}

</style>

<script type="text/javascript">
window.onload = function() {
var oIco = document.getElementById("ico");
var aBtn = oIco.getElementsByTagName("a");
var oSlide = document.getElementById("slide");
var oUl = oSlide.getElementsByTagName("ul");
var aLi = oUl[0].getElementsByTagName("li");
var oBtnLeft = document.getElementById("btnLeft");
var oBtnRight = document.getElementById("btnRight");

var baseWidth = aLi[0].offsetWidth;
//alert(baseWidth);
oUl[0].style.width = baseWidth * aLi.length + "px";
var iNow = 0;
for(var i=0;i<aBtn.length;i++) {
aBtn[i].index = i;
aBtn[i].onclick = function() {
//alert(this.index);
//alert(oUl[0].style.left);
move(this.index);
//aIco[this.index].className = "active";
}
}
oBtnLeft.onclick = function() {
iNow ++;
//document.title = iNow;
move(iNow);
}
oBtnRight.onclick = function() {
iNow --;
document.title = iNow;
move(iNow);
}

var curIndex = 0;
var timeInterval = 1000;
setInterval(change,timeInterval);
function change() {
if(curIndex == aBtn.length) {
curIndex =0;
} else {
move(curIndex);
curIndex += 1;
}

}

function move(index) {
//document.title = index;
if(index>aLi.length-1) {
index = 0;
iNow = index;
}
if(index<0) {
index = aLi.length - 1;
iNow = index;
}
for(var n=0;n<aBtn.length;n++) {
aBtn[n].className = "";
}
aBtn[index].className = "active";
oUl[0].style.left = -index * baseWidth + "px";
//buffer(oUl[0],{
// left: -index * baseWidth
// },8)

}
}
</script>
</head>
<body>
<div id="slide">
<a id="btnLeft" href="javascript:void(0);" ></a>
<a id="btnRight" href="javascript:void(0);" ></a>
<!--when change next image:style="left: -(n-1)*800px;"-->
<ul>
<li><img src="images/anniu.png" alt="" /></li>
<li><img src="images/zhu2.png" alt="" /></li>
<li><img src="images/xiangqing5.png" alt="" /></li>
<li><img src="images/wanle.png" alt="" /></li>
</ul>
<div id="ico" class="ico">
<a class="active" href="javascript:void(0);"></a>
<a href="javascript:void(0);"></a>
<a href="javascript:void(0);"></a>
<a href="javascript:void(0);"></a>
<a href="javascript:void(0);"></a>
<a href="javascript:void(0);"></a>
</div>
</div>
</body>
</html>

相关文章

  • Javascript 两个窗体之间传值实现代码

    Javascript 两个窗体之间传值实现代码

    众所周知window.open() 函数可以用来打开一个新窗口,那么如何在子窗体中向父窗体传值呢,其实通过window.opener即可获取父窗体的引用。
    2009-09-09
  • JS技巧之一行赋值语句能玩出多少花样

    JS技巧之一行赋值语句能玩出多少花样

    很多前端只会谢谢页面,一让他们接触js,就非常害怕,下面这篇文章主要给大家介绍了关于JS技巧之一行赋值语句能玩出多少花样的相关资料,需要的朋友可以参考下
    2022-10-10
  • 微信小程序返回箭头跳转到指定页面实例解析

    微信小程序返回箭头跳转到指定页面实例解析

    这篇文章主要介绍了微信小程序返回箭头跳转到指定页面实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-10-10
  • Javascript 读取操作Sql中的Xml字段

    Javascript 读取操作Sql中的Xml字段

    把Xml字段先读出来,然后用Js去操作,这样岂不是简单了许多,于是网上搜索了一些JS读Xml字段信息的方法
    2014-10-10
  • js行号显示的文本框实现效果(兼容多种浏览器 )

    js行号显示的文本框实现效果(兼容多种浏览器 )

    本文主要介绍了javascript实现行号显示的文本框效果,这样就可以解决读者很难迅速找到所在某一行的对应代码,感兴趣的小伙伴们可以参考一下
    2015-10-10
  • 原生JS实现飞机大战小游戏

    原生JS实现飞机大战小游戏

    这篇文章主要为大家详细介绍了原生JS实现飞机大战小游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-06-06
  • AJAX请求与跨域问题解决方法详解

    AJAX请求与跨域问题解决方法详解

    学习ajax必须得掌握的就是跨域请求,实际上在不同源的地址上发送请求就是跨域请求,本文主要给大家介绍了关于AJAX请求以及解决跨域问题的相关资料,需要的朋友可以参考下
    2022-11-11
  • 小程序实现横向滑动日历效果

    小程序实现横向滑动日历效果

    这篇文章主要介绍了小程序实现横向滑动日历效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-10-10
  • javascript中replace使用方法总结

    javascript中replace使用方法总结

    这篇文章主要为大家详细介绍了javascript中replace的使用方法,使用replace和正则表达式共同实现字符串trim方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-03-03
  • layui扩展上传组件模拟进度条的方法

    layui扩展上传组件模拟进度条的方法

    今天小编就为大家分享一篇 layui扩展上传组件模拟进度条的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-09-09

最新评论