By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

Can Somebody Check This?

P: n/a
I'm trying to create a script that will cycle through a bunch of pics
(1.jpg, 2.jpg, and so on up to 429.jpg) to make a movie. However, I
can't get it to work. Could someone tell me what I'm doing wrong?
Here it is...

<html>

<head>

<script>
pics = new Array()
curPic = 0

preLoad() {
for (i=0; i <= 429; i++) {
pics[i] = new Image()
pics[i].src = i + ".jpg"
}
}

dispPic() {
document.images['moviePic'].src = curPic + ".jpg"
curPic++
setTimeout("dispPic()", 20)
}
</script>

</head>

<body>

<body onload="preLoad(); dispPic()">

<img src="1.jpg" name="moviePic" width="640" height="416">

</body>

</html>
Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
chris wrote on 03 mei 2004 in comp.lang.javascript:
<html>

<head>

<script>
pics = new Array()
curPic = 0

preLoad() {
for (i=0; i <= 429; i++) {
pics[i] = new Image()
pics[i].src = i + ".jpg"
}
}

dispPic() {
document.images['moviePic'].src = curPic + ".jpg"
curPic++
setTimeout("dispPic()", 20)
}
</script>

</head>

<body>

<body onload="preLoad(); dispPic()">

<img src="1.jpg" name="moviePic" width="640" height="416">

</body>

</html>


Functions are declared with the word "function"
Preloading should be done BEFORE the onload=""
20 ms could be to short for some systems

[declare script type]
[use the preloaded entity]
[declare curPic with a var.]
[No double <body>]
[declare "px" in sizes]
<html>
<head>
<script type="text/javascript">
var pics = new Array()
var curPic = 0

for (i=0; i <= 429; i++) {
pics[i] = new Image()
pics[i].src = i + ".jpg"
}

function dispPic() {
document.images['moviePic'].src = pics[curPic++].src
setTimeout("dispPic()", 20)
}
</script>
</head>
<body onload="dispPic()">
<img src="1.jpg" name="moviePic" width="640px" height="416px">
</body>
</html>

not tested, btw.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2

P: n/a
Ivo
"Evertjan." wrote
[declare "px" in sizes]
<img src="1.jpg" name="moviePic" width="640px" height="416px">


First time I 've seen units declared in simple width and height attributes.
Are you not confused with widths and heights coming from css? But I tried
and found it works (tested in IE6)!
How far backward compatible is this? I 'm sure this wasn't necessary before.
Ivo
Jul 23 '05 #3

P: n/a
On Tue, 4 May 2004 13:31:06 +0200, Ivo <no@thank.you> wrote:
"Evertjan." wrote
[declare "px" in sizes]
<img src="1.jpg" name="moviePic" width="640px" height="416px">


First time I 've seen units declared in simple width and height
attributes.
Are you not confused with widths and heights coming from css? But I
tried and found it works (tested in IE6)!
How far backward compatible is this? I 'm sure this wasn't necessary
before.


You are correct: it wasn't and isn't necessary. In fact, I believe it's
erroneous.

The width and height attributes for the IMG element are of type "Length".
Length may either be a "Pixel" value or a percentage. Therefore,
width="640" is automatically stating 640 pixels. No units are necessary,
and are probably incorrect if used.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4

P: n/a
Evertjan. wrote:
function dispPic() {
document.images['moviePic'].src = pics[curPic++].src
setTimeout("dispPic()", 20)
}
</script>
</head>


What happens when you reach 429?
Mick

Jul 23 '05 #5

P: n/a
On 4-May-2004, Michael Winter <M.******@blueyonder.co.invalid> wrote:
width="640" is automatically stating 640 pixels. No units are necessary,
and are probably incorrect if used.


Specifying the default in most languages is rarely incorrect even if unnecessary.
It just helps to make the information very specific. HTML and its variants
specify that "px" is a legitimate qualifier; why should it be incorrect to use it?

Mike
Jul 23 '05 #6

P: n/a
"Michael Daly" <mi*********@foo.bar> writes:
On 4-May-2004, Michael Winter <M.******@blueyonder.co.invalid> wrote:
width="640" is automatically stating 640 pixels. No units are necessary,
and are probably incorrect if used.

.... HTML and its variants specify that "px" is a legitimate qualifier;
why should it be incorrect to use it?


No it doesn't.
<URL:http://www.w3.org/TR/html4/types.html#h-6.6>
The valid values of an HTML length is either pixels (a plain number) or
percentages (a number with "%" after).

Units like "px" are CSS, not HTML. You can use them in they style tag,
but that is CSS content. It should not be used in the width property
(but one should use CSS instead of the width property in any case -
it's even deprecated on HR, TD, TH, and PRE elements).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #7

P: n/a
On 4-May-2004, wrote:
Units like "px" are CSS, not HTML.


You're right - I stand corrected. What a Babel we've got here!

Mike
Jul 23 '05 #8

P: n/a
Ivo wrote:
"Evertjan." wrote
[declare "px" in sizes]
<img src="1.jpg" name="moviePic" width="640px" height="416px">
First time I 've seen units declared in simple width and height attributes.
Are you not confused with widths and heights coming from css? But I tried
and found it works (tested in IE6)!


That's one of the Bad Things about IE for developers:
It turns every sh*t into gold.
How far backward compatible is this?
I 'm sure this wasn't necessary before.


It is worng, simple as that.
PointedEars
Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.