无法使用 jQuery 对边框颜色进行动画处理
Can't animate the border color with jQuery
我有这个表:
<table id="social" border="5">
<tr>
<td>
<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fyannbane.blogspot.com%2F&send=false&layout=button_count&width=100&show_faces=true&action=like&colorscheme=light&font&height=21&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);
但结果相同...你是怎么做到的?
来自 jQuery animate 参考(我的强调)
所有已动画处理的属性都应动画化为单个数值, 除非下文另有说明;大多数非数字属性不能 使用基本的 jQuery 功能进行动画处理(例如,宽度、 高度或左侧可以动画,但背景色不能, 除非使用 jQuery.Color() 插件)。处理属性值 除非另有说明,否则为像素数。单位 em 和 % 可以在适用的情况下指定。
简而言之,看起来您要么需要 Color() 插件,要么需要自己动手。
安德鲁对这个问题的回答似乎只需要很少的工作。
您绝对应该像其他人已经指出的那样使用 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 演示
这是关于这项技术的另一个答案。
相关文章:
- jQuery动画-边框宽度和颜色
- 如何用jquery动画改变背景颜色,就像一个过渡
- 我需要在javascript if语句中使用jquery来动画元素的颜色
- 在划桨点击时更改 HTML 画布乒乓动画中圆圈的颜色
- 在 JavaScript 中为其添加动画效果时更改图像颜色
- AngularJs设置背景颜色/颜色的动画
- 使用CSS或SVG设置与背景颜色匹配的文本颜色的动画
- 背景颜色更改时需要动画
- jQuery 在滚动背景上动画颜色不变
- 动画背景颜色,脉冲效果
- 减少jQuery颜色动画的加载时间
- 如何使此更改边框颜色动画停止
- 在paper.js中设置颜色动画
- jQuery颜色动画相对于元素'当前颜色(色调、饱和度、亮度)
- React颜色动画同步
- 如何用渐变颜色动画文本
- 在React Native中设置背景颜色动画
- Jquery计数器与背景颜色动画
- 用tween.js分配颜色动画Three.js
- 悬停时导航的背景颜色动画