Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    lse
    lse is offline
    New Coder
    Join Date
    Oct 2009
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts

    style.left.length/style.left.substr

    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???

    Code:
    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";
      }
    }

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,240
    Thanks
    12
    Thanked 340 Times in 336 Posts
    images[i].style.left is the CSS left property (a string). then there are applied

    the substr() method
    and the length property is read.

  • #3
    lse
    lse is offline
    New Coder
    Join Date
    Oct 2009
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,240
    Thanks
    12
    Thanked 340 Times in 336 Posts
    Quote Originally Posted by lse View Post
    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?

    Quote Originally Posted by lse View Post
    style.left.length is a number of how many chars in string?
    how shall I know, it’s not my CSS.

  • #5
    lse
    lse is offline
    New Coder
    Join Date
    Oct 2009
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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
    Code:
      <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?

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,240
    Thanks
    12
    Thanked 340 Times in 336 Posts
    ain’t that obvious?

  • #7
    lse
    lse is offline
    New Coder
    Join Date
    Oct 2009
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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'

    ???

  • #8
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,240
    Thanks
    12
    Thanked 340 Times in 336 Posts
    bingo


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •