[英]change class css using jquery
I have a class which uses a media query: 我有一个使用媒体查询的类:
css: CSS:
@media only screen and (min-width: 58.75em)
.top-bar-section ul li {
border-left: 1px solid #fff;
transform: skewX(15deg);
}
Now if the value of City()
is London I want to change that css above to say: 现在,如果
City()
值为London,我想将上面的css更改为这样:
@media only screen and (min-width: 58.75em)
.top-bar-section ul li {
border-left: 1px solid #fff;
transform: skewX(-15deg);
}
My javascript is: 我的JavaScript是:
if (City() == "London"){
//change the css class from the first example to the 2nd?
}
Any help on how I can do this with jQuery to change a classes css? 关于如何使用jQuery更改类CSS的任何帮助? Thanks, Josh
谢谢,乔希
For specifying the css you can use the .css()
-function of jQuery: 要指定css,可以使用jQuery的
.css()
函数:
$('.top-bar-section ul li').css({
'-webkit-transform' : 'skewX(-15deg)',
'-moz-transform' : 'skewX(-15deg)',
'-ms-transform' : 'skewX(-15deg)',
'-o-transform' : 'skewX(-15deg)',
'transform' : 'skewX(-15deg)'
});
Or you can specify a second class, eg: 或者,您可以指定第二类,例如:
.top-bar-section ul li.london {
transform: skewX(-15deg);
}
and call 并打电话
$('.top-bar-section ul li').addClass('london');
inside your if-condition. 在您的if条件中。 For removing the class you can use
.removeClass()
要删除该类,可以使用
.removeClass()
Reference 参考
是的,你可以使用jQuery的帮助下做的,加入的jQuery newClass
如果指定的条件为真,并使用jQuery removeClass
反之亦然。
您可以使用addClass和removeClass方法来实现。
您可以使用带有class属性的jQuery来更改类,这是文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.