2

我有这张桌子:

<table id="social" border="5">
    <tr>
        <td>
            <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fyannbane.blogspot.com%2F&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21&amp;appId=177127339057410" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>
        </td>

        <td>
            <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://yannbane.blogspot.com/" data-via="Yannbane">Tweet</a>
        </td>

        <td>
            <g:plusone></g:plusone>
        </td>
    </tr>
</table>

我想用jquery为其边界设置动画,如下所示:

$("#social").animate({"borderTopColor": "#f00", "borderBottomColor": "#fff"}, 800);

但是,它不起作用!什么都没有发生,甚至没有显示错误......

我也试过这个:

$("#social").animate({"border-top-tolor": "#f00", "border-bottom-color": "#fff"}, 800);

但结果相同......你是怎么做到的?

4

2 回答 2

7

来自jQuery animate 参考(我的重点)

所有动画属性都应动画为单个数值,除非以下说明;大多数非数字属性无法使用基本的 jQuery 功能进行动画处理(例如,宽度、高度或左侧可以进行动画处理,但背景颜色不能进行动画处理, 除非使用 jQuery.Color() 插件)。除非另有说明,否则属性值被视为像素数。可以在适用的情况下指定单位 em 和 %。

简而言之,看起来您要么需要Color()插件,要么需要自己开发。

安德鲁对这个问题的回答似乎可以做你需要做的很少的工作。

于 2012-05-01T12:51:59.763 回答
3

正如其他人已经指出的那样,您绝对应该使用 Color 插件。

但是,作为旁注,您可以使用一种有趣的技术来代替动画变量(在本例中为color变量),然后在step函数中执行您的操作。

这可能有点矫枉过正,但给你很大的灵活性来做自定义动画:

// animate color variable from 0x0 to 0xF
$({ color: 0 }).animate({ color: 15}, {
    duration: 800,
    step: function(now, fx) {
        var hexValue = Math.round(now).toString(16);
        $("#social").css({
            'border-top-color': '#' + hexValue + '00',
            'border-bottom-color': '#' + hexValue + hexValue + hexValue
        });
    }
});

jsfiddle 演示

这是有关此技术的另一个答案。

于 2012-05-01T13:29:13.703 回答