views:

199

answers:

2

i am trying to display my products animation with the following code (jquery)

var prodNum = <%=prodNum %>;
var i = 1;  
$.timer(5000, function(timer) {     
    $(".prods").hide("slide", { direction: "down" }, 500, function() { 
        $(".prods").html("<div class=\"prod\">" + $("#pr" + ((4*i) % prodNum)).html() + "</div>" + 
                        "<div class=\"prod\">" + $("#pr" + ((4*i + 1) % prodNum)).html() + "</div>" + 
                        "<div class=\"prod\">" + $("#pr" + ((4*i + 2) % prodNum)).html() + "</div>" + 
                        "<div class=\"prod\">" + $("#pr" + ((4*i + 3) % prodNum)).html() + "</div>");
        $(".prods").show("slide", { direction: "down" }, 500);
        i++;
     });


});

It works fine with firefox, but in IE i get "Out of memory at line: 13" How can i fix this? I am using version 1.4.2

Thanks

A: 

Inside your method instead of using $(".prods") inside the method, use $(this), like this:

var prodNum = <%=prodNum %>;
var i = 1;  
$.timer(5000, function(timer) {     
  $(".prods").hide("slide", { direction: "down" }, 500, function() { 
    $(this).html("<div class='prod'>" + $("#pr" + ((4*i) % prodNum)).html() + "</div>" + 
                 "<div class='prod'>" + $("#pr" + ((4*i + 1) % prodNum)).html() + "</div>" + 
                 "<div class='prod'>" + $("#pr" + ((4*i + 2) % prodNum)).html() + "</div>" + 
                 "<div class='prod'>" + $("#pr" + ((4*i + 3) % prodNum)).html() + "</div>")
           .show("slide", { direction: "down" }, 500);
    i++;
  });
});

When you use $(".prods") it's animating each element interdependently (and times n elements, since every .hide() that finished queues every other new .prod element as well, it's exponentially compounding the animations). With all the slide animations within each other and queuing per element, IE won't be too happy with this many animations going at once.

Nick Craver
I replaced the $(".prods") with $(this) but i still get the same error
junkqwe
@junkqwe - How many of these elements are there?
Nick Craver
+1  A: 

Found the problem. It was a computability between the jqery and the jquey.ui versions

Thanks

junkqwe
I had an "out of memory at line:" issue in IE only using jquery 1.3.2. I updated to 1.4.2 and the problem went away. Is that what happened for you?
MrBoJangles