admin管理员组文章数量:1336631
I have this table:
<table id="social" border="5">
<tr>
<td>
<iframe src="//www.facebook/plugins/like.php?href=http%3A%2F%2Fyannbane.blogspot%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="" class="twitter-share-button" data-url="/" data-via="Yannbane">Tweet</a>
</td>
<td>
<g:plusone></g:plusone>
</td>
</tr>
</table>
And I'd like to animate its borders with jquery, like this:
$("#social").animate({"borderTopColor": "#f00", "borderBottomColor": "#fff"}, 800);
But, it doesn't work! Nothing happens at all, even no errors are shown...
I've also tried this:
$("#social").animate({"border-top-tolor": "#f00", "border-bottom-color": "#fff"}, 800);
But with same results... How do you do this?
I have this table:
<table id="social" border="5">
<tr>
<td>
<iframe src="//www.facebook./plugins/like.php?href=http%3A%2F%2Fyannbane.blogspot.%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./share" class="twitter-share-button" data-url="http://yannbane.blogspot./" data-via="Yannbane">Tweet</a>
</td>
<td>
<g:plusone></g:plusone>
</td>
</tr>
</table>
And I'd like to animate its borders with jquery, like this:
$("#social").animate({"borderTopColor": "#f00", "borderBottomColor": "#fff"}, 800);
But, it doesn't work! Nothing happens at all, even no errors are shown...
I've also tried this:
$("#social").animate({"border-top-tolor": "#f00", "border-bottom-color": "#fff"}, 800);
But with same results... How do you do this?
Share edited Oct 10, 2017 at 19:04 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked May 1, 2012 at 12:47 corazzacorazza 32.4k39 gold badges120 silver badges191 bronze badges 2- 1 possible duplicate of jQuery animate border color on hover? – epascarello Commented May 1, 2012 at 12:50
- 1 @epascarello There's no indication the OP is using the Color plugin – Basic Commented May 1, 2012 at 12:52
2 Answers
Reset to default 7From the jQuery animate reference (my emphasis)
All animated properties should be animated to a single numeric value, except as noted below; most properties that are non-numeric cannot be animated using basic jQuery functionality (For example, width, height, or left can be animated but background-color cannot be, unless the jQuery.Color() plugin is used). Property values are treated as a number of pixels unless otherwise specified. The units em and % can be specified where applicable.
In short, it looks like you either need the Color() plugin or you need to roll your own.
Andrew's answer on this question seems to do what you need for very little work.
You should definitely use the Color plugin as others already pointed out.
However, as a side note, you can use instead an interesting technique that consists animating variables (in this case color
variable) and then do your stuff in the step
function.
This might be a bit overkill, but gives you lots of flexibility to do custom animations:
// 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 demo
Here is another answer regarding this tecnhique.
本文标签: javascriptCan39t animate the border color with jQueryStack Overflow
版权声明:本文标题:javascript - Can't animate the border color with jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742404579a2468558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论