[英]How to pass media queries with jQuery CSS method
I have a media query like this:我有一个这样的媒体查询:
@media (min-width: 768px) {
.navbar-nav > li > a {
padding-top: 25px;
padding-bottom: 25px;
}
}
I need to change the style like:我需要改变风格,如:
$( "#heightSet" ).change(function() {
var choice = $(this).val();
if (choice == "50"){
$(".navbar-nav > li > a").css({"padding-top":"15px","padding-bottom":"15px"});
}
if (choice == "60"){
$(".navbar-nav > li > a").css({"padding-top":"20px","padding-bottom":"20px"});
}
});
How can I take care of the @media (min-width: 768px)
on the .CSS()
so the code is affected only on that specific view port?我如何处理.CSS()
上的@media (min-width: 768px)
.CSS()
以便代码仅在该特定视口上受到影响?
.my-class-15 {padding-top: 15px; padding-bottom: 15px;}
.my-class-20 {padding-top: 20px; padding-bottom: 20px;}
$("#heightSet").change(function () {
var choice = $(this).val();
if (choice == "50") {
$(".navbar-nav > li > a").addClass('my-class-15');
}
if (choice == "60") {
$(".navbar-nav > li > a").addClass('my-class-20');
}
});
Here's a fiddle, but it's not very useful without your HTML.这是一个小提琴,但如果没有您的 HTML,它就不是很有用。
http://jsfiddle.net/isherwood/nf5tP/ http://jsfiddle.net/isherwood/nf5tP/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.