madmatter23
01-27-2009, 04:26 AM
Hello,
I'm trying to improve a working script that slows down with high data volume.
Here's what it does:
When a thumbnail is rolled over, a corresponding div containing a larger image fades in (animate/opacity) elsewhere on the page.
When another thumb is rolled over, the class of larger image divs fades out, then the new div fades in.
With lots of thumbs, this gets slow. Each larger image div is dynamically written to html through php and hidden with css (opacity & display) until the jQuery fades it in, so from my understanding, those images are already loaded in the brower's cache. How can I reduce the lag in this animation? It's fine with a few thumbs, but very slow with a lot.
Any help would be appreciated. Thank you.
function thumb_to_mid(target_items, name){ //target items are rolled over, name is class of objects being animated
$("."+name+":first").css({"display" :"block"}).animate({"opacity" :"1"}, 2500);
if($(target_items).attr("rel") != "" && $(target_items).attr("rel") != "undefined" ){ //check to make sure rel isn't blank, then:
$(target_items).hover( function(){
var div_id = $(this).attr("rel"); //grab this elements rel attribute
var this_mid_div = $("#"+div_id); //set var for mid image element
$("."+name).animate({"opacity" :"0"}, 100); //fade out previous mid pic
$("."+name).css({"display" :"none"}); //hid previous mid pic
this_mid_div.css({"display" :"block"}); //show current mid pic
this_mid_div.animate({"opacity" :"1"}, 500); //fade in current mid pic
});
}
}
Here's an example of the page with only 2 thumbs. (http://www.stephenshaheen.com/piece.php?piece_id=2#)
Here's an example of the page with a lot of thumbs. (http://www.stephenshaheen.com/piece.php?piece_id=28#)
I'm trying to improve a working script that slows down with high data volume.
Here's what it does:
When a thumbnail is rolled over, a corresponding div containing a larger image fades in (animate/opacity) elsewhere on the page.
When another thumb is rolled over, the class of larger image divs fades out, then the new div fades in.
With lots of thumbs, this gets slow. Each larger image div is dynamically written to html through php and hidden with css (opacity & display) until the jQuery fades it in, so from my understanding, those images are already loaded in the brower's cache. How can I reduce the lag in this animation? It's fine with a few thumbs, but very slow with a lot.
Any help would be appreciated. Thank you.
function thumb_to_mid(target_items, name){ //target items are rolled over, name is class of objects being animated
$("."+name+":first").css({"display" :"block"}).animate({"opacity" :"1"}, 2500);
if($(target_items).attr("rel") != "" && $(target_items).attr("rel") != "undefined" ){ //check to make sure rel isn't blank, then:
$(target_items).hover( function(){
var div_id = $(this).attr("rel"); //grab this elements rel attribute
var this_mid_div = $("#"+div_id); //set var for mid image element
$("."+name).animate({"opacity" :"0"}, 100); //fade out previous mid pic
$("."+name).css({"display" :"none"}); //hid previous mid pic
this_mid_div.css({"display" :"block"}); //show current mid pic
this_mid_div.animate({"opacity" :"1"}, 500); //fade in current mid pic
});
}
}
Here's an example of the page with only 2 thumbs. (http://www.stephenshaheen.com/piece.php?piece_id=2#)
Here's an example of the page with a lot of thumbs. (http://www.stephenshaheen.com/piece.php?piece_id=28#)