听起来微不足道,但我如何才能真正检查这一点?我在 SASS 中有以下断点:
$width_breakpoints: (
small: 39.9375em,
medium: 40em,
large: 76em
);
现在我想检查以下内容(伪代码):
if($(window).width() < 39.9375em) {
// add current-mode-mobile class to a certain element
}
如何实际检查宽度是否小于 X em 或 X rem 或 X%?
最佳答案
对于 IE10+:
if (window.matchMedia("(min-width: 39.9375em)").matches) {
/* the viewport is at least 39.9375 em wide */
} else {
/* the viewport is less than 39.9375 em wide */
}
关于javascript - jQuery:检查窗口是否小于像素以外的 x 单位(例如 em、rem)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49363333/