如果屏幕分辨率发生变化,如何在jquery中进行检测? [英] How to detect in jquery if screen resolution changes?

查看:126
本文介绍了如果屏幕分辨率发生变化,如何在jquery中进行检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用户每次更改屏幕分辨率大小(而不是浏览器窗口)时页面都能执行功能?

How can I make it so that each time when user changes the screen resolution size [not the browser window], the page perform a function?

推荐答案

好,所以您正在使用jQuery.因此,让我们为其创建一个自定义事件.

Ok, so you're using jQuery. So let's make a custom event for it.

(function () {
    var width = screen.width,
        height = screen.height;
    setInterval(function () {
        if (screen.width !== width || screen.height !== height) {
            width = screen.width;
            height = screen.height;
            $(window).trigger('resolutionchange');
        }
    }, 50);
}());

现在$(window).bind('resolutionchange', fn)应该执行您想要的操作.

Now $(window).bind('resolutionchange', fn) should do what you want.

这篇关于如果屏幕分辨率发生变化,如何在jquery中进行检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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