Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Wierd and annoying image.onload problem!
Old 11-06-2008, 04:00 PM Wierd and annoying image.onload problem!
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Im messing around with the .onload event handler for images, and am finding the results to be a little confusing??

I have the following script to change the display properties for some images:
Code:
function showImage ()
    {
        this.style.display = 'none';
        alert (this.nodeName);
    }

function loading ()
    {
        var portThumbImg = document.getElementById ('portThumbAll').getElementsByTagName ('img');
        
        for (i = 0; i < portThumbImg.length; i ++)
            {
                portThumbImg[i].onload = showImage;
            }
        
        
        var content = document.getElementById ('content');
    }

    
loading ();
Im testing it locally, which I think might be causing the problem, as the results seem to be different each time I run the script! Its supposed to hide all of the images each when they are loaded.

sometimes it will hide all of them, and sometimes it will just hide a few! The images are inside a div, and Ive placed the script tag just before the </div>

Im guessing that since Im testing it locally its something to do with the images already being loaded? Or loading too fast or something? I don't know.

But I would have thought that even if the images have been loaded before, you could still use the .onload event reliably each time you refreshed the page?
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 11-07-2008, 07:37 PM Re: Wierd and annoying image.onload problem!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
If the div hasn't closed it won't exist in the DOM

define the functions early, but don't call the loading function until the div has been closed.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-09-2008, 05:47 AM Re: Wierd and annoying image.onload problem!
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Now I get ya! Thanks.
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Reply     « Reply to Wierd and annoying image.onload problem!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12329 seconds with 12 queries