简体   繁体   English

javascript-当浏览器窗口调整为特定宽度时,禁用浏览器窗口调整大小

[英]javascript - Disable Browser Window Resize, when Browser window resized to certain width

I am working on a script where i want to restrict the resize of browser window when we resize the browser to width 320px. 我正在编写一个脚本,当我们将浏览器的大小调整为320px时,我想限制浏览器窗口的大小。 The screen should not shrink below 320px. 屏幕不应缩小到320像素以下。

Here is my code!! 这是我的代码!

        var waitForFinalEvent = (function() {
          var timers = {};
          return function(callback, ms, uniqueId) {
            if (!uniqueId) {
              uniqueId = "Don't call this twice without a uniqueId" ;
            }
            if (timers[uniqueId]) {
              clearTimeout(timers[uniqueId]);
            }
            timers[uniqueId] = setTimeout(callback, ms);
          };
        })();

        // Usage
        $(window).resize(function() {
          var output = $('.output');
          $(output).text('RESIZING...');
          // Wait for it...
          waitForFinalEvent(function() {
            $(output).text('EVENT FIRED!');
            //...
          }, 500, "some unique string");
        });

Try this 尝试这个

$(window).resize(function(){
    if ($(window).width() <= 320) {
       window.resizeTo(300 ,$(window).height());
    }
});

If your window is resized to less than 320 force the window to resize to 320 x whatever the current height is. 如果将窗口调整为小于320的大小,则无论当前高度如何,都强制将窗口调整为320 x。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM