Different values when debugging than in console?

时间:2015-07-29 00:28:40

标签: javascript css angularjs

I'm running an Angular application that is returning two distinct values simultaneously. I'm curious if anyone has seen this:

#this is a NumPy array
npdata = ([somedata, '2014-07-01 08:18:21', somedata, somedata, somedata, somedata, etc], 
[somedata, '2014-07-01 10:01:40', somedata, somedata, somedata, somedata, etc], etc...])

This is straightforward as can be. Switch which item is "active", and then force a render refresh. You'll notice none of this code is really doing anything, but thats okay. I left out some of the less important, unrelated stuff.

Yep, I'm frustrated enough that I'm trying to force the render refresh in multiple ways at once.

In the chrome debugger, if you break on this line:

function updateValues() {
    var activeNavButton = pageNavButtons.eq(values.currentPage);
    pageNavButtons.removeClass("active");
    activeNavButton.addClass("active");

    pageNavButtons.each(function () {
        var forceRender = $(this).get(0).offsetLeft;
    });

    var w = 0;
    $(".pages button").each(function () {
        w = w + $(this).outerWidth(true)
    });
    var b=0;

    completeHandler();
}

the following occurs:

var b = 0

However, if you open the console while the script is still at that break point and literally copy and paste the preceding 4 lines:

w = 790 //Watcher

It returns 800 for the value of w. An important thing to note: the .active class gives the selected element a "bold" font, thus changing the element width. I'm positive this is related to the problem but I can't for the life of me figure out what the issue really is.

As you can see, I'm accessing offsetWidth to try to force the browser to update the elements but its not working.

Any ideas? This is driving me absolutely insane.

1 个答案:

答案 0 :(得分:1)

好。这可能看起来很愚蠢,但在大型代码基础上,它可能并不令人惊讶:

事实证明,按钮的基本CSS类(层次结构中的一种方式)有一个转换:全部150毫秒。

这会导致延迟,导致宽度错误地返回,正如您所期望的那样,这是重要的部分,字体权重包含在转换全部中。

因此,字体重量将在150ms之后改变,并且那些额外的宽度像素(在某些情况下)会记录#34;晚期"。难怪我的计时器似乎任意成功:我在猜测。

获得的经验:不要使用过渡:除非你有充分的理由。定位您想要实际转换的内容。

希望这有助于其他人!欢呼声。