【发布时间】:2021-01-19 12:05:14
【问题描述】:
当我删除 if() {} 时,此代码可以正常工作,但我希望 css 样式仅适用于特定的窗口宽度。当我添加 if 语句时,它不再读取 CSS 样式。知道为什么吗?
$(document).ready(function() {
$(".icon").mousemove(function() {
$(this).hide();
$(".second").show(2000);
if (windows.innerWidth > 768) {
$(".second").css({
"display": "grid",
"grid-template": "200px / 200px 200px"
});
}
});
});
I also tried this and still not working:
$(document).ready(function(){
$(".icon").mousemove(function() {
$(this).hide();
$(".second").show(2000);
if ($(window).width() > 768){
$(".second").css({
"display": "grid",
"grid-template": "200px / 200px 200px"
});
}
else {
$(".second").css({
"display": "grid",
"grid-template": "100px / 100px 100px"
});
}
});
});
【问题讨论】:
-
您可以使用媒体查询。
-
你能添加一个关于你的问题的工作示例的 sn-p 吗?
it doesn't read the CSS style anymore是什么意思?
标签: javascript jquery css