2

I have this piece of code and it actually works fine, yet I have a spurious line in there and it won't work without it for some reason.

It picks up the hover color from the css via jquery and animates that hover (between colors) for browsers that dont have css transitions. ( I am using modernizr to detect the feature). The problem is that if I remove the variable declaration var ie8and9dec = quickbarcolorhover; ( which has no other use at all, it's just there to trigger whatever makes this work ) then it will not work at all for IE8 and IE9 ... (so probably just wont work at all as I think all the other browsers I've used don't need this code in the first place).

Does anyone know why this would be the case? It will also work if I replace the declaration with console.log(quickbarcolorhover);, and that's how I discovered it. I would rather not have this spurious piece of code if I can avoid it.

$(function() {
    var quickbar = $(".no-csstransitions #quick-bar a");
    quickbarcolor = quickbar.css("color");

    quickbar.hover(function () {
        if ( $(this).css("color") != quickbarcolor) {
            quickbarcolorhover = $(this).css("color");
        }
        var ie8and9dec = quickbarcolorhover; /* this dec has no purpose but code wont work without it */
        $(this).children().css("color", quickbarcolor).animate({ color: quickbarcolorhover } ,400 );
    }, function() {
        $(this).children().animate({ 'color': quickbarcolor} ,400 )
    }  
    );
});
4

1 回答 1

1

以防万一它对其他人有任何帮助,我将描述我为解决此问题所做的工作。

我正在使用 wordpress,我发现 wordpress 已经包含 jQuery UI;所以我所做的是删除我最初用于动画功能的 JqueryUI 代码的一部分(有一个插件可以使用,但我选择包含 JqueryUI 代码)所以现在我替换了这段代码排队(在我的functions.php文件中)到jqueryUI核心和JqueryUI效果核心,因此通过完全不同的(并且在wordpress术语中更好)方法包括JqueryUI。

然后我使用的代码也略有改变,但实际上我认为代码不是问题,因为它可能与我使用的 jQueryUI 代码与 wordpress 中包含的 Jquery 代码不同步有关。

$(function() {
    var quickbar = $(".no-csstransitions #quick-bar a");
    var quickbarcolor = quickbar.css("color");

    quickbar.hover(function () {
            if ( $(this).css("color") != quickbarcolor) quickbarcolorhover = $(this).css("color");
            $(this).find("*").css("color", quickbarcolor).animate({ color: quickbarcolorhover } , 400 );
        }, function() {
            $(this).find("*").animate({ 'color': quickbarcolor} ,400 )
        }
    );
});
于 2013-03-11T15:05:04.103 回答