-1

For some reason Javascript stops working randomly.

Code that is dealing with height problem:

$(document).ready(function() 
{ 

    /*setEqualHeight($("ul#product_list li"));*/
    //alert("some text");
    /*setEqual($("ul#product_list"));*/
    //var i = 2;
    //alert($('ul#product_list li:nth-child('+ (i + 2) +')').height()); //this is correct way to get value*/
    var elements = $('ul#product_list li').length; //this is correct way to get value
    /*var liekana = elements % 3;
    elements = elements - liekana;
    alert(elements);*/
    for(var i = 1; i <= elements; i = i + 3)
    {
        var first = $('ul#product_list li:nth-child('+ (i) +')').height();
        var second = $('ul#product_list li:nth-child('+ (i + 1) +')').height();
        var third = $('ul#product_list li:nth-child('+ (i + 2) +')').height();
        var tallest = 0;
        if (first > second)
            if (first > third)
            {
                tallest = first; 
            }
            else 
            {
                tallest = third;
            }
        else
            if (second > third)
            {
                tallest = second;
            }
            else
            {
                tallest = third;
            }
        $('ul#product_list li:nth-child('+ (i) +')').height(tallest);
        $('ul#product_list li:nth-child('+ (i + 1) +')').height(tallest);
        $('ul#product_list li:nth-child('+ (i + 2) +')').height(tallest);
        /*if (!third)
            alert("yra");*/
    }
});

Failing URL: http://piguskompiuteris.lt/6_asus Normal render URL: http://piguskompiuteris.lt/16-lenovo

Any suggestions how to solve this problem would be greatly appreciated. Thanks

UPDATE 2. I have rewriten javascript code... I still get the same random errors, sometimes grid collapses. I am not sure what is the cause.

Possible causes: 1) Height attribute is too small and doesn't include height + padding + margin + border 2) There is something wrong with function placement (currently not in header) or calling it $(document).ready(function()

4

2 回答 2

0

排序脚本有效。

要修复脚本使用:

$(window).load(function() {});

出而不是:

$(document).ready(function() {});

于 2013-05-01T18:04:08.333 回答
0

我已经检查了你的网站。并发现这个解决方案使用它:

columns.height(tallestcolumn);

将上面的代码替换为以下代码:

columns.css("min-height", tallestcolumn+" !imporatant");

这对你有用。

于 2013-05-01T09:32:14.360 回答