始终检查窗口大小(jquery)

Check window size always (jquery)

本文关键字:jquery 窗口大小 检查      更新时间:2023-09-26

我想检查浏览器是否有安全像素大小。这是我的尝试:

var height = $(".size_fullscreen").height();
var width = $(".size_fullscreen").width();
if (height == 1024 && width == 768) {
    alert("please flip");
}

起初这对我来说很有效,但现在我想一直检查这个脚本。因此,如果尺寸发生变化,应该弹出类似"谢谢"之类的内容。

我认为jquery中有文档准备功能,但我没有得到它的解决方案。

有人能帮我吗?非常感谢。

试试这个

 $document.ready(function(){
    /** Functions to call on Window Resize**/
    var ResizeTimer;
    $(window).on("resize", function(){
        clearTimeout(ResizeTimer);
        ResizeTimer = setTimeout(function(){
        // Add your functions here
        var wH = $(".size_fullscreen").height();
        var wW = $(".size_fullscreen").width();
          if (wH == 1024 && wW == 768) {
                 alert("please flip");
          }
       // wait for 200ms between each resize event
        },200); 
    });
    // Call your function on DOM ready / Trigger resize
    $(window).trigger('resize');
});

如果你想检查你一直写的脚本,那么就把它放在窗口调整事件中。

示例:

$(window).resize(function() {
 var height = $(window).height();
 var width = $(window).width();
if (height == 1024 && width == 768) {
    alert("please flip");
}
});