Posts: 165
Location: Santa Monica, CA
|
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..
|