如何在媒体查询中禁用JavaScript [英] How to disable JavaScript in media query

查看:81
本文介绍了如何在媒体查询中禁用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在媒体查询中删除javascripts。

I want to dissable javascripts in media query.

@media only screen
 (max-device-width : 568px) {
.sidebar { display: none; } 
  #navmenu {  margin-top:0px; width:auto; padding:10px; margin-left:15%;}
.content {width:auto; height:auto; margin-left:0; margin-top:3%;}
.contentsing{position:relative; width:100%; height:auto; margin-left:0%; margin-top:-150px;}


}

这是mu代码,现在我想添加一些会禁用脚本的东西。

That is mu code, now i want to add something that will disable scripts.

推荐答案

你可以将你的脚本包装在if语句中检查屏幕的宽度如下:

You could wrap your script in an if statement that checks how wide the screen is like this:

if(window.innerWidth > 568){
    ...execute script
}

然而,这只会执行一次,所以如果你调整大小怎么办?你的浏览器窗口?每当您调整浏览器大小时,您都可以拥有一个执行脚本的事件监听器。

However, that will only execute once, so what if you resize your browser window? You could have an event listener that executes your script whenever you resize the browser.

window.addEventListener('resize', function(){
    if(window.innerWidth > 568){
        ...execute script
    }
});

这篇关于如何在媒体查询中禁用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆