0

関数removeCell()が呼び出されると、Firefoxがフリーズします。

この関数を使用して、ウィンドウの幅に応じて、いくつかのグリッドセルを非表示にします。
グリッドの準備ができた後、ウィンドウのサイズを変更するたびに、関数はリグスと呼ばれます。
ChromeとOperaでは問題なく動作しますが、Firefoxでは最初の呼び出しの直後にスタックします。

function removeCell(){
    headerResize();
    if (($('.section .header .cell:last-child').position().left + $('.section .header .cell:last-child').width()) > 
        $('.section .header').position().left + $('.section .header').width())
    {
        var priority = $body_grid_header[0].priority;
        var index    = 0;

        for(var i in $body_grid_header){
            if(bool($body_grid_header[i].visible) && $body_grid_header[i].priority > priority){
                priority = $body_grid_header[i].priority;
                index    = i;
            }
        }
        $body_grid_header[index].visible = 0;
        $('.grid .header .cell:nth-child('+ (parseInt(index)+2) +')').addClass('hidden');

        $hiddenArray.unshift(index);
        headerResize();
        removeCell();
    }
    else
    {
        //console.log($body_grid_header);
        var firstCell   = $('.grid .header .cell:first-child').width();
        var lastCell    = $('.grid .header .cell:last-child').width();
        var headerWidth = $('.grid .header').width();
        var cellCount   = $('.grid .header .cell').not(':first').not(':last').not('.hidden').length;

        if ((cellCount*100 + 100+firstCell+lastCell < headerWidth) && (cellCount < $body_grid_header.length))
        {
            var index = $hiddenArray[0];
            $hiddenArray.splice(0,1);

            $body_grid_header[index].visible = 1;
            $('.grid .header .cell:nth-child('+ (parseInt(index)+2) +')').removeClass('hidden');
            headerResize();
            removeCell(); //I GUESS IT STUCKS HERE!
        }
    }
}


function headerResize(){
  var firstColl = $('.grid .header .coll:first-child').width();
  var lastColl  = $('.grid .header .coll:last-child').width();
  var headerWidth   = $('.grid .header').width() - firstColl - lastColl;
  var collCount = $('.grid .header .coll').not(':first').not(':last').not('.hidden').length;
  var collWidth     = headerWidth / collCount - 1; //-1 = border-left

  if(collWidth < 100) collWidth = 100;

  $('.section .header .coll').not(':first').not(':last').width(collWidth);
  $('.section .content .coll:not(:first-child)').width(collWidth);

}

4

2 に答える 2

0

従うのは難しく、ローカルでテストするのは本当に難しいです:-)

試しに、変更します

if ((cellCount*100 + 100+firstCell+lastCell < headerWidth) && (cellCount < $body_grid_header.length))

if ((cellCount*100 + 100+firstCell+lastCell < headerWidth) && $hiddenArray.length)

それがうまくいくことを願っています...

于 2012-08-21T12:13:02.360 に答える
0

The code can cause a deadlock in any browser since it boils down to:

removeCell() {
     removeCell();
}

The only thing that prevents that is the if() in the else branch:

if ((cellCount*100 + 100+firstCell+lastCell < headerWidth) && (cellCount < $body_grid_header.length))

If this condition is wrong, you have an endless loop.

Instead of recursive calls, you should really work with a loop and break out of it when all cells have been removed.

于 2012-08-21T11:58:44.563 に答える