Error while using jquery animate “Out of memory at line: 13”

旧街凉风 提交于 2019-12-12 09:58:14

问题


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


回答1:


Found the problem.

It was a computability between the jQuery and the jQuery.ui versions

Thanks




回答2:


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.



来源:https://stackoverflow.com/questions/3501123/error-while-using-jquery-animate-out-of-memory-at-line-13

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!