Reply
How do you install an onload event handler?
Old 11-02-2009, 06:41 PM How do you install an onload event handler?
World's Avatar
Extreme Talker

Posts: 165
Location: Santa Monica, CA
Trades: 0
I have this Javascript photo gallery problem: the fade doesn't work, as the image only loads when you click on it.

I want all images first loaded, and only then I want the gallery to be ready.

Code:
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
        $('#gallery img').each(function(i) {
    var imgFile = $(this).attr('src');
    
        
    $(this).hover(
        function() {
            $(this).attr('src', preloadImage.src);
        },
        function () {
        var currentSource=$(this).attr('src');
            $(this).attr('src', imgFile);
    }); // end hover
}); // end each

    
// script 7.2 below this line
    $('#gallery a').click(function(evt) {
        evt.preventDefault();
        var imgPath = $(this).attr('href');
        var oldImage = $('#photo img');
        var newImage = $('<img src="' + imgPath + '">');
        newImage.hide();
        $('#photo').prepend(newImage);
        newImage.fadeIn(1000);
        oldImage.fadeOut(1000,function() {
        $(this).remove();
        }); //end fadeOut function
    }); 
    
    //end click
    $('#gallery a:first').click();
    }); // end ready
</script>
edit: how can I make the images load in the background?

Last edited by World; 11-02-2009 at 07:24 PM..
World is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-02-2009, 07:23 PM Re: How do you install an onload event handler?
World's Avatar
Extreme Talker

Posts: 165
Location: Santa Monica, CA
Trades: 0
To load all image files before the Javascript gallery functions, would I need to replace

Code:
$(document).ready(function() {
with

Code:
$(document).load {
???

Last edited by World; 11-02-2009 at 07:37 PM..
World is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 12:39 AM Re: How do you install an onload event handler?
World's Avatar
Extreme Talker

Posts: 165
Location: Santa Monica, CA
Trades: 0
What I mean is: how can you make sure images load in the background?

With this script above they only load when you click on them.
World is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How do you install an onload event handler?
 

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.10877 seconds with 13 queries