Javascript图像滚动不与DOCTYPE一起使用

编程入门 行业动态 更新时间:2024-10-26 19:39:58
本文介绍了Javascript图像滚动不与DOCTYPE一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在努力寻找一些JavaScript代码,让我可以在网页上自动滚动图像。经过漫长的搜索,我终于找到了足够接近的东西。然后我尽可能地对它进行了定制,以使其完成我想要的功能。

这个测试是在没有DOCTYPE的页面上完成的,所以当我移动它转到一个有DOCTYPE的页面,javascript被搞砸了,并且拒绝滚动。它只显示了一个固定的图像(在safari和firefox上)。

我已将这两个网页上传到我的MobileMe网站,以便您可以看一看。

没有DOCTYPE的网页: web.me / zubby

具有DOCTYPE的页面: web.me/zubby/2.html

javascript也在下面详细介绍。我会非常感激,如果有人可以帮助我。

我只上传相关文件,所以萤火虫可能会抱怨不存在的功能。

var pic = new Array(); function banner(name,width,link){ this.name = name this.width = width this.link = link } ; pic [0] = new banner('images / cellarpics / cellarbynightsmall.jpg',203,'images / cellarpics / cellarbynightsmall.jpg'); pic [1] = new banner('images / cellarpics / insidecellarnewsmall.jpg',203,'images / cellarpics / insidecellarnewsmall.jpg'); pic [2] = new banner('images / cellarpics / mainshotwebsmall.jpg',203,'images / cellarpics / mainshotwebsmall.jpg'); pic [3] = new banner('images / cellarpics / MicroCelllar2tileopensmall.jpg',203,'images / cellarpics / MicroCelllar2tileopensmall.jpg'); pic [4] = new banner('images / cellarpics / openmicrosmall.jpg',203,'images / cellarpics / openmicrosmall.jpg'); pic [5] = new banner('images / cellarpics / topopenweb1small.jpg',203,'images / cellarpics / topopenweb1small.jpg'); pic [6] = new banner('images / cellarpics / topweb2small.jpg',203,'images / cellarpics / topweb2small.jpg'); pic [7] = new banner('images / cellarpics / topwebclosed1small.jpg',203,'images / cellarpics / topwebclosed1small.jpg'); / * 图片[8] =新横幅('www.sxc.hu/pic/s/d/da/da9l/290444_yellow_rose.jpg'102,'http:/ /www.sxc.hu/pic/m/d/da/da9l/290444_yellow_rose.jpg') * / var speed = 10; var kk = pic.length; var ii; var hhh; var nnn; var myInterval; var myPause; var mode = 0; var imgArray = new Array(kk); var myLeft = new Array(kk); (ii = 0; ii< kk; ii ++){ imgArray [ii] = new Image() imgArray [ii] .src = pic [ii]的 。名称 imgArray [ii] .width = pic [ii] .width hhh = 0 (nnn = 0; nnn

解决方案

原因在于使用doctype时,设置css声明的工作方式不同,似乎只有一个数字是不够的......为了使其工作,在此函数中使用autoscroll()

变更

document.images [ii] .style.left = myLeft [ii]

document.images [ii] .style.left = myLeft [ii] +px

另外,您的两个脚本不会加载,menu.js和js / prettyPhoto.js

I've been searching the net hard for some javascript code that allows me to automatically scroll images non-stop horizontally on a webpage. After a long time searching, I finally came across something that was close enough. I then customised it as much as possible to make it do exactly what I wanted it to do.

This testing was done on a page without a DOCTYPE, so when I moved it over to a page that had a DOCTYPE, the javascript got messed up and refused to scroll. It just showed a single stationary image (on safari and firefox)

I've uploaded both webpages to my MobileMe site so you guys can have a look.

The page without a DOCTYPE: web.me/zubby

The page with a DOCTYPE: web.me/zubby/2.html

the javascript is also detailed below. I'll be extremely thankful if someone can help me out with this.

I only uploaded the relevant files so firebug will probably complain about non-existent functions.

var pic = new Array(); function banner(name, width, link){ this.name = name this.width = width this.link = link }; pic[0] = new banner('images/cellarpics/cellarbynightsmall.jpg',203,'images/cellarpics/cellarbynightsmall.jpg'); pic[1] = new banner('images/cellarpics/insidecellarnewsmall.jpg',203,'images/cellarpics/insidecellarnewsmall.jpg'); pic[2] = new banner('images/cellarpics/mainshotwebsmall.jpg',203,'images/cellarpics/mainshotwebsmall.jpg'); pic[3] = new banner('images/cellarpics/MicroCelllar2tileopensmall.jpg',203,'images/cellarpics/MicroCelllar2tileopensmall.jpg'); pic[4] = new banner('images/cellarpics/openmicrosmall.jpg',203,'images/cellarpics/openmicrosmall.jpg'); pic[5] = new banner('images/cellarpics/topopenweb1small.jpg',203,'images/cellarpics/topopenweb1small.jpg'); pic[6] = new banner('images/cellarpics/topweb2small.jpg',203,'images/cellarpics/topweb2small.jpg'); pic[7] = new banner('images/cellarpics/topwebclosed1small.jpg',203,'images/cellarpics/topwebclosed1small.jpg'); /* pic[8] = new banner('www.sxc.hu/pic/s/d/da/da9l/290444_yellow_rose.jpg',102,'www.sxc.hu/pic/m/d/da/da9l/290444_yellow_rose.jpg') */ var speed = 10; var kk = pic.length; var ii; var hhh; var nnn; var myInterval; var myPause; var mode = 0; var imgArray = new Array(kk); var myLeft = new Array(kk); for (ii=0;ii<kk;ii++){ imgArray[ii] = new Image() imgArray[ii].src = pic[ii].name imgArray[ii].width = pic[ii].width hhh=0 for (nnn=0;nnn<ii;nnn++){ hhh=hhh+pic[nnn].width }; myLeft[ii] = hhh }; function ready(){ for (ii=0;ii<kk;ii++){ if (document.images[ii]plete == false){ return false break }; }; return true }; function startScrolling(){ if (ready() == true){ window.clearInterval(myPause) myInterval = setInterval("autoScroll()",speed) }; }; function autoScroll(){ for (ii=0;ii<kk;ii++){ myLeft[ii] = myLeft[ii] - 1 if (myLeft[ii] == -(pic[ii].width)){ hhh = 0 for (nnn=0;nnn<kk;nnn++){ if (nnn!=ii){ hhh = hhh + pic[nnn].width }; }; myLeft[ii] = hhh }; document.images[ii].style.left = myLeft[ii] }; mode = 1 }; function stop(){ if (mode == 1){ window.clearInterval(myInterval) }; if (mode == 0){ window.clearInterval(myPause) }; }; function go(){ if (mode == 1){ myInterval = setInterval("autoScroll()",speed) }; if (mode == 0){ myPause = setInterval("startScrolling()",3000) }; }; myPause = setInterval("startScrolling()",100) for (ii=0;ii<kk;ii++){ document.write('<a href="' + pic[ii].link + '" target="_blank"><img style="height:131px;position:absolute;top:0;left:' + myLeft[ii] + ';" src="' + pic[ii].name + '" onMouseOver="stop()" onMouseOut="go()" /></a>'); };

解决方案

In IE it works. The reason is that with doctype, setting css declaration left works differently, seems that only a number is not enough...to make it work, in this function autoscroll()

Change

document.images[ii].style.left = myLeft[ii]

to

document.images[ii].style.left = myLeft[ii] + "px"

Also, two of your scripts don't load, menu.js and js/prettyPhoto.js

更多推荐

Javascript图像滚动不与DOCTYPE一起使用

本文发布于:2023-11-17 03:47:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608715.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不与   图像   Javascript   DOCTYPE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!