根据窗口大小禁用JavaScript插件 [英] disabling javascript plugin based on window size

查看:87
本文介绍了根据窗口大小禁用JavaScript插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个实质上为三个不同断点(台式机,平板电脑,移动设备)设计的网站进行编码.我有一个javascript插件,可为我的全角背景运行自动图像更改.当我将窗口调整为平板电脑和移动断点的大小时,我可以禁用javascript插件并在窗口小于*** px时停止运行吗?

I'm coding a website essentially for three different breakpoints (desktop, tablet, mobile). I have a javascript plugin running an automatic image change for my full width background. As I resize my window to the tablet and mobile breakpoints, can I disable the javascript plug in and make it stop running when the window is smaller than ***px?

推荐答案

var minWidth = 800 // minimum width of screen
if ($(window).width() <= minSize) {
     // do nothing
}
else {
     // continue script
}

如果您希望宽度和高度都一样:

If you wanted it to be width as well as height:

if ($(window).width() <= minWidth && $(window).height() <= minHeight) {

或类似的东西.

这篇关于根据窗口大小禁用JavaScript插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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