多个css规则与三元运算符 [英] Multiple css rules with ternary operator
本文介绍了多个css规则与三元运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 .hover()
事件中,我有以下代码:
Within a .hover()
event, I have the following code:
$(this).css('background-position', circle.includesXY(e.pageX, e.pageY) ? 'bottom' : '');
可能有人解释如何添加更多属性:值对到 .css ()
而不损害三元运算符?如果没有,应该如何重写呢?
Could somebody explain how I can add more property:value pairs to .css()
without compromising the ternary operator? If not, how should it be rewritten?
推荐答案
.css
接受一个对象:
$(this).css(circle.includesXY(e.pageX, e.pageY)
? {
property1: 'value1',
property2: 'value2'
}
: {
property1: 'value3',
property2: 'value4'
}
);
这篇关于多个css规则与三元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文