当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 点图片上一页下一页翻页效果

Javascript
AJAX教程(14):通过XMLHTTP加载XML文件
AJAX教程(15):通过XMLHTTP进行一次HEAD请求
AJAX教程(16):通过XMLHTTP进行一次指定的HEAD请求
AJAX教程(17):把XML文件显示为HTML表格
JS通过WMI获取客户端硬件信息
JavaScript中使用远程脚本
关于Ajax技术的注意事项
XMLHttpRequest创建智能表单
iframe创建智能表单
JS教程:线小测试程序
在Web页面中使用计时器
将事件处理器作为HTML标记的属性
事件处理器作为浏览器对象的属性
Math对象应用详解
random()方法和pow()方法
charAt()方法和charCodeAt()方法
Number对象常用的toFixed()方法
JS教程:为什么尽量用局部变量代替全局变量
解决JavaScript循环中的过多操作
处理提示“脚本运行时间过长的提示框”问题

Javascript 中的 点图片上一页下一页翻页效果


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 335 ::
收藏到网摘: n/a

实现图片翻页效果实例代码 <script language="javascript" defer>
var zhang=2
function next(){
if(zhang==7){
alert("这已经是最后一张了!")
zhang=6
}
document.getElementById("tu").src=zhang+".jpg"
text.innerHTML="当前是第"+zhang+"张图片"
zhang++
}
function up(){
if(zhang==2){
alert("这已经是第一张了!")
zhang=3
}
document.getElementById("tu").src=(zhang-2)+".jpg"
text.innerHTML="当前是第"+(zhang-2)+"张图片"
zhang--
}
</script>
<style type="text/css">
#divall {
position:relative;
}
#divleft {
border:1px red solid;
border-right:0px red solid;
background: url(bg.gif);
cursor:url("2.cur");
position:absolute;
top:0px;
z-index:2007;
text-align:right;
padding:0px
}
#divright {
border:1px red solid;
border-left:0px red solid;
background: url(bg.gif);
cursor:url("1.cur");
top:0px;
position:absolute;
z-index:2007
text-align:center;
padding:0px
}
#tu{z-index:-2007}
</style>
<div id="text" >当前是第1张图片</div>
<div id="divall">
<img src="1.jpg" id="tu">
<div id="divleft" title="上一张" onmouseover="show_div('divleft','left.gif')" onmouseout="hide_div('divleft')" onclick="up()">
</div>
<div id="divright" title="下一张" onmouseover="show_div('divright','right.gif')" onmouseout="hide_div('divright')" onclick="next()">
</div>
</div>
<script>//
var w=document.getElementById("tu").width//500
var h=document.getElementById("tu").height//400
document.getElementById("tu").style.width=w
document.getElementById("tu").style.height=h
//document.getElementById("divleft").style.visibility='hidden'
document.getElementById("divleft").style.width=w/2
document.getElementById("divleft").style.height=h
document.getElementById("divleft").style.left=0
//document.getElementById("divright").style.visibility='hidden'
document.getElementById("divright").style.width=w/2
document.getElementById("divright").style.height=h
document.getElementById("divright").style.left=w/2
//document.write("<style> #tu{width:"+w+"px; height:"+h+"px;z-index:2000}</style>")
function show_div(id,img){
document.getElementById(id).innerHTML="<img src="+img+">"
}
function hide_div(id){
document.getElementById(id).innerHTML=""
}
</script>