【发布时间】:2014-04-23 06:33:37
【问题描述】:
我知道 matchMedia.js,但我想我可以像这样简单地检测当前的@media 规则。但是,它在 firefox 中不起作用——(这通常意味着它一开始就不正确……)现在看看,内容不应该在 :after 伪元素上吗?有什么建议吗?我有一个CodePen HERE:
CSS
#test {
content: "small"
}
@media only screen and (min-width: $bp1) {
#test {
content: "medium"
}
}
jQuery
>var sizeCheck = function() {
if ( $("#test").css('content') === 'small') {
$('.proof').text('jQuery knows this page is SMALL from reading the CSS @media rules.');
} else if ( $("#test").css('content') === 'medium') {
$('.proof').text('jQuery knows this page is MEDIUM from reading the CSS @media rules.');
}
};
// run the function on document ready
$(document).ready(sizeCheck);
// AND run the function on window resize event
$(window).resize(sizeCheck);
【问题讨论】:
-
看看这篇文章:css-tricks.com/…
标签: javascript jquery css media-queries