[英]Jquery + CSS default BG color
I have a div with a css style of say green or blue, depending on the nth child color. 我有一个css样式的div,例如绿色或蓝色,具体取决于第n个子颜色。 I set it to orange using 我将其设置为橙色
<div id='yo' class='alternatingcolors' style='background-color: #FF9900;'>hello</div>
and I want to animate it back to its original color using jquery's 我想使用jQuery的将其动画化回其原始颜色
$('yo').animate({ backgroundColor: 'transparent'}, 500);
However, neither transparent, inherit, null, or '' work. 但是,透明,继承,空值或''都不起作用。
How would I get it back to its original color? 我如何将其恢复为原始颜色? Essentially I want to animate it to the state before: style='background-color: #FF9900;' 本质上,我想将其设置为以前的状态:style ='background-color:#FF9900;' was set. 被设定。
The lookup to 'yo' should be prefixed with a hash, eg: 对“ yo”的查找应以哈希作为前缀,例如:
$('#yo')
If that's not the issue: 如果那不是问题:
You could store the original colour as data in the div, then restore it later: 您可以将原始颜色作为数据存储在div中,然后稍后将其还原:
<div id='yo' data-original-color='#FF9900' class='alternatingcolors'>
then: 然后:
$('#yo').animate({ backgroundColor: $('#yo').data('original-color') }, 500);
您可以将其第一个背景色保存为变量,然后使用它:
orange = $("yo").css("background-color")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.