PDA

View Full Version : style.left.length/style.left.substr


lse
01-19-2010, 07:41 PM
I am reading:
Head First Ajax Code: Chapter 5, Asychronous Applications
http://headfirstlabs.com/books/hfajax/ch05.php

since is AJAX book does NOT explain normal js code, well can you tell what mean:

images[i].style.left.substr
images[i].style.left.length, what these do???

function scrollImages() {
var coverBarDiv = document.getElementById("coverBar");
var images = coverBarDiv.getElementsByTagName("img");
for (var i = 0; i < images.length; i++) {
var left = images[i].style.left.substr(0, images[i].style.left.length - 2);
if (left <= -86) {
left = 532;
}
images[i].style.left = (left - 1) + "px";
}
}

Dormilich
01-19-2010, 08:35 PM
images[i].style.left is the CSS left property (a string). then there are applied

the substr() (https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/substr) method
and the length property is read.

lse
01-19-2010, 09:01 PM
images[i].style.left is the CSS left property ,... is it number? is string, what string?
style.left.length is a number of how many chars in string?

Dormilich
01-19-2010, 10:47 PM
images[i].style.left is the CSS left property ,... is it number? is string

images[i].style.left is the CSS left property (a string)

just curious, what do you know about CSS?

style.left.length is a number of how many chars in string?

how shall I know, it’s not my CSS.

lse
01-20-2010, 08:20 AM
About css I read a small book p250 expecially for this and Javascript books and jsp/servlets books that somewhat describe it....

well given the
<div id="coverBar">
<img src="images/coverMatrix.jpg" width="82" height="115" style="left: 0px;" />
<img src="images/coverDeadRingers.jpg" width="82" height="115" style="left: 88px;" />
<img src="images/coverDrStrangelove.jpg" width="82" height="115" style="left: 176px;" />
<img src="images/coverFuturama.jpg" width="82" height="115" style="left: 264px;" />
<img src="images/coverHolyGrail.jpg" width="82" height="115" style="left: 356px;" />
<img src="images/coverRaisingArizona.jpg" width="82" height="115" style="left: 444px;" />
<img src="images/coverRobotChicken.jpg" width="82" height="115" style="left: 532px;" />
</div>
can you tell what
images[i].style.left.substr or
images[i].style.left.length

may consist/be?

Dormilich
01-20-2010, 08:36 AM
ain’t that obvious?

lse
01-20-2010, 10:46 PM
you mean if we have style="left: 88px;"

images[i].style.left.length=4
images[i].style.left.substr(0, images[i].style.left.length - 2)='88'

???

Dormilich
01-21-2010, 12:33 AM
bingo