show/ hide stuff help needed

Discussion in 'JavaScript' started by Fracisc, Mar 31, 2011.

  1. #1
    I have this:
    
    <a href="javascript:ajaxpage('http://www.mysite.com', 'contentarea');">
    <img class="thumbnail" src="image.jpg" width="500" onmouseover="this.src='inprogress.gif';" />
    </a>
    <div id="contentarea"></div>
    
    Code (markup):
    This code will display an image and, when clicked, it will load an URL in the "contentarea" div and replace the image with a "loading" image. This part works great BUT I need to make that loading image disappear in 5 seconds and get back the original image.

    Basically this is what I need:
    - image displayed
    - when clicked, a "loading" image is displayed over/instead of the standard image for 5 seconds, after the 5 seconds I need my original image back
    - also, when clicked, I should be able to keep the javascript:ajaxpage('http://www.mysite.com', 'contentarea');" part.

    Any idea on how I can do that?
     
    Fracisc, Mar 31, 2011 IP
  2. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #2
    use setTimeout
     
    artus.systems, Mar 31, 2011 IP
  3. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #3
    I am not sure how..
     
    Fracisc, Mar 31, 2011 IP
  4. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
  5. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #5
    Uhm... it seems that I am unable to make it work...
     
    Fracisc, Mar 31, 2011 IP
  6. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #6
    I have a question. Why you won't change it at the end of the AJAX request? Why after 5 seconds? I think it can confuse the user. Because user may think that request is done after 5 seconds, but probably isn't...
     
    Jan Novak, Mar 31, 2011 IP
  7. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #7
    When they click the image I am loading an URL that processes something. In about 5 seconds the processing is done. That's why I need a 5 sec image rollover.
     
    Fracisc, Mar 31, 2011 IP
  8. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #8
    try this if you have asynchronous ajax:

    
    <script type="text/javascript">
    function loadLateImg(){
        window.setTimeout("document.images['img'].src='image2.jpg'",5000)
    }
    </script>
    <a href="javascript:ajaxpage('http://www.mysite.com', 'contentarea');loadLateImg();">
    <img id="img" class="thumbnail" src="image.jpg" width="500" onmouseover="this.src='inprogress.gif';" />
    </a>
    <div id="contentarea"></div>
    
    
    Code (markup):
     
    Jan Novak, Mar 31, 2011 IP
    Fracisc likes this.
  9. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #9
    That worked. Thanks!
     
    Fracisc, Apr 1, 2011 IP
  10. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #10
    Great! You are welcome!
     
    Jan Novak, Apr 1, 2011 IP