Results 1 to 4 of 4

Thread: Move image up the page

  1. #1
    Join Date
    Dec 2005
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Move image up the page

    I found a js code that'll move an image from left to right when the image is clicked on and changed it to move an image up. But it only works in IE. What needs to be changed or added to get it to work in Firefox?
    Code:
    function moveit(spot){
    if (document.layers){
    var picture=document.all.image;
    if (spot<500){
    picture.bottom=spot; spot+=1; setTimeout('moveit('+spot+')',1);
    }
    }
    if (document.all){
    var picture=document.all.image.style;
    if (spot<500){
    picture.bottom=spot; spot+=1; setTimeout('moveit('+spot+')',1);
    }
    }
    }

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Hard to say without knowing what image stands for but, if it is the id of the image in question then this will do:

    Code:
    function moveit(spot){
    if (document.layers){
    var picture=document.all.image;
    if (spot<500){
    picture.bottom=spot; spot+=1; setTimeout('moveit('+spot+')',1);
    }
    }
    if (document.all||document.getElementById){
    var picture=document.all? document.all.image.style : document.getElementById('image').style;
    if (spot<500){
    picture.bottom=spot; spot+=1; setTimeout('moveit('+spot+')',1);
    }
    }
    }
    If, on the other hand, image is a variable containing a value equivalent to the id of the image, get rid of the red single quotes. If image is something else, a different approach is needed.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2005
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks John, that works perfectly.
    Sorry for not specifying what image was for. I would have posted the html too if I'd realized it mattered, but you were correct in assuming it was the id.

    In my feeble attempts to get it to work I did some surfing and figured getElementById had to go in there somewhere, just had no idea how. Am I correct that's the standard DOM method, document.all is IE specific, and document.layers is for older versions of Netscape? If so, is document.layers really even needed, since there can't be that many people still using older versions?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yes, getElementById is standard DOM and supported by all modern browsers, including IE6. The older version support never hurts. I bet there are at least 100's of thousands of old NS4 browsers still in use though. Compare that to the millions (billions?) of modern browsers, and that isn't much. Who knows? Maybe your site will attract the NS4 crowd. I once worked on a project for use in the developing world and all of that had to be IE5.0 compliant.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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