首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

上面这个代码是图片轮换的代码,在ie里好用在火狐不好用 如何调呢 多谢了

2012-09-13 
下面这个代码是图片轮换的代码,在ie里好用在火狐不好用怎么调呢谢谢了下面这个代码是图片轮换的代码,在ie

下面这个代码是图片轮换的代码,在ie里好用在火狐不好用 怎么调呢 谢谢了
下面这个代码是图片轮换的代码,在ie里好用在火狐不好用 怎么调呢 谢谢了



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>


<BODY bgcolor="#fef4d9" onload=initiate()>

<SPAN id=imgcontainer1 style="HEIGHT: 19px; LEFT: 22px; POSITION: absolute; TOP: -65px; WIDTH: 721px"></SPAN>
<SPAN id=imgcontainer2 style="HEIGHT: 25px; LEFT: 13px; POSITION: absolute; TOP: -37px; WIDTH: 722px"></SPAN>
<SCRIPT type="text/javascript">

// The width of your images (pixels). All pictures should have the same width.
var imgwidth=261

// The height of your images (pixels). All pictures should have the same height.
var imgheight=219

// The horizontal and vertical position of the images (pixels). 
var pos_left=70
var pos_top=90

// The name of your images. You may add as many images as you like.
var imgname=new Array()
imgname[0]="images/1.jpg"
imgname[1]="images/2.jpg"
imgname[2]="images/3.jpg"
imgname[3]="images/11.jpg"
imgname[4]="images/12.gif"

// Where should those images be linked to? 
// Add an URL for each image.
// If you don't want to add an URL just write '#' instead of 
// the URL, see sample imgurl[2].
var imgurl=new Array()
imgurl[0]="http://www.7stk.com"
imgurl[1]="http://www.7stk.com"
imgurl[2]="http://www.7syg.com"
imgurl[3]="http://www.7syg.com"
imgurl[4]="http://www.7syg.com"

// This block will preload your images. Do not edit this block.
var imgpreload=new Array()
for (i=0;i<=imgname.length-1;i++) {
imgpreload[i]=new Image()
imgpreload[i].src=imgname[i]
}

// Standstill-time between the images (microseconds).
var pause=2000

// Speed of the stretching and shrinking effect. More means slower.
var speed=20

// This variable also affects the speed (the length of the step between each inmage-frame measured in pixels). More means faster.
var step=10

// Do not edit the script below
var i_loop=0
var i_image1=0
var i_image2=1


function stretchimage() {
if (i_loop<=imgwidth) {
if (document.all) {
imgcontainer1.innerHTML="<a href='"+imgurl[i_image1]+"' target='_blank'><img width='"+i_loop+"' height='"+imgheight+"' src='"+imgname[i_image1]+"' border='0'></a>"
document.all.imgcontainer2.style.posLeft=document.all.imgcontainer1.style.posLeft+i_loop

imgcontainer2.innerHTML="<a href='"+imgurl[i_image2]+"' target='_blank'><img width='"+(imgwidth-i_loop)+"' height='"+imgheight+"' src='"+imgname[i_image2]+"' border='0'></a>"
}
i_loop=i_loop+step
var timer=setTimeout("stretchimage()",speed)
  }
else {
clearTimeout(timer)
changeimage()
}
}

function changeimage() {
i_loop=0
i_image1++
if (i_image1>imgname.length-1) {i_image1=0}
i_image2=i_image1-1
if (i_image2>imgname.length-1) {i_image2=0}
if (i_image2<0) {i_image2=imgname.length-1}

document.all.imgcontainer2.style.posLeft=document.all.imgcontainer1.style.posLeft
  var timer=setTimeout("stretchimage()",pause)
}

function initiate() {
if (document.all) {
document.all.imgcontainer1.style.posLeft=pos_left


document.all.imgcontainer2.style.posLeft=pos_left
document.all.imgcontainer1.style.posTop=pos_top
document.all.imgcontainer2.style.posTop=pos_top
changeimage()
}
if (document.layers) {
document.imgcontainer1.left=pos_left
document.imgcontainer2.left=pos_left
document.imgcontainer1.top=pos_top
document.imgcontainer2.top=pos_top
rotatenetscape()
}
}

function rotatenetscape() {
document.imgcontainer1.document.write("<a href='"+imgurl[i_image1]+"' target='_blank'><img src='"+imgname[i_image1]+"' border='0'></a>")
document.imgcontainer1.document.close()
i_image1++
if (i_image1>imgname.length-1) {i_image1=0}
  var timer=setTimeout("rotatenetscape()",pause*2)
}
</SCRIPT>


[解决办法]
document.all火狐不识别的
改成document.getElementsByTagName之类的试试
[解决办法]
获取dom节点方法不兼容,document.all只有IE支持,document.layers是Netscape 4.x专有的属性。改用document.getElementById来获取就行了。我大概改了一下,有些无用的代码我没有删除,你自己调整吧。

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title></head><BODY bgcolor="#fef4d9" onload=initiate()><SPAN id=imgcontainer1 style="HEIGHT: 19px; LEFT: 22px; POSITION: absolute; TOP: -65px; WIDTH: 721px"></SPAN><SPAN id=imgcontainer2 style="HEIGHT: 25px; LEFT: 13px; POSITION: absolute; TOP: -37px; WIDTH: 722px"></SPAN><SCRIPT type="text/javascript">// The width of your images (pixels). All pictures should have the same width.var imgwidth=261// The height of your images (pixels). All pictures should have the same height.var imgheight=219// The horizontal and vertical position of the images (pixels).var pos_left=70var pos_top=90// The name of your images. You may add as many images as you like.var imgname=new Array()imgname[0]="images/1.jpg"imgname[1]="images/2.jpg"imgname[2]="images/3.jpg"imgname[3]="images/11.jpg"imgname[4]="images/12.gif"// Where should those images be linked to?// Add an URL for each image.// If you don't want to add an URL just write '#' instead of// the URL, see sample imgurl[2].var imgurl=new Array()imgurl[0]="http://www.7stk.com"imgurl[1]="http://www.7stk.com"imgurl[2]="http://www.7syg.com"imgurl[3]="http://www.7syg.com"imgurl[4]="http://www.7syg.com"// This block will preload your images. Do not edit this block.var imgpreload=new Array()for (i=0;i<=imgname.length-1;i++) {imgpreload[i]=new Image()imgpreload[i].src=imgname[i]}// Standstill-time between the images (microseconds).var pause=2000// Speed of the stretching and shrinking effect. More means slower.var speed=20// This variable also affects the speed (the length of the step between each inmage-frame measured in pixels). More means faster.var step=10// Do not edit the script belowvar i_loop=0var i_image1=0var i_image2=1function stretchimage() {if (i_loop<=imgwidth) {if (document.getElementById) {document.getElementById("imgcontainer1").innerHTML="<a href='"+imgurl[i_image1]+"' target='_blank'><img width='"+i_loop+"' height='"+imgheight+"' src='"+imgname[i_image1]+"' border='0'></a>"document.getElementById("imgcontainer2").style.posLeft=document.getElementById("imgcontainer1").style.posLeft+i_loopdocument.getElementById("imgcontainer2").innerHTML="<a href='"+imgurl[i_image2]+"' target='_blank'><img width='"+(imgwidth-i_loop)+"' height='"+imgheight+"' src='"+imgname[i_image2]+"' border='0'></a>"}i_loop=i_loop+stepvar timer=setTimeout("stretchimage()",speed)  }else {clearTimeout(timer)changeimage()}}function changeimage() {i_loop=0i_image1++if (i_image1>imgname.length-1) {i_image1=0}i_image2=i_image1-1if (i_image2>imgname.length-1) {i_image2=0}if (i_image2<0) {i_image2=imgname.length-1}document.getElementById("imgcontainer2").style.posLeft=document.getElementById("imgcontainer1").style.posLeft  var timer=setTimeout("stretchimage()",pause)}function initiate() {if (document.getElementById) {document.getElementById("imgcontainer1").style.posLeft=pos_leftdocument.getElementById("imgcontainer2").style.posLeft=pos_leftdocument.getElementById("imgcontainer1").style.posTop=pos_topdocument.getElementById("imgcontainer2").style.posTop=pos_topchangeimage()}if (document.layers) {document.imgcontainer1.left=pos_leftdocument.imgcontainer2.left=pos_leftdocument.imgcontainer1.top=pos_topdocument.imgcontainer2.top=pos_toprotatenetscape()}}function rotatenetscape() {document.getElementById("imgcontainer1").document.write("<a href='"+imgurl[i_image1]+"' target='_blank'><img src='"+imgname[i_image1]+"' border='0'></a>")document.getElementById("imgcontainer1").document.close()i_image1++if (i_image1>imgname.length-1) {i_image1=0}  var timer=setTimeout("rotatenetscape()",pause*2)}</SCRIPT> 

热点排行