screen.width不检查窗口大小 [英] screen.width not checking for a window resize

查看:112
本文介绍了screen.width不检查窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用此脚本来查看正在访问我的网站的用户的屏幕宽度是否小于800.我的问题是,我还希望在用户将其屏幕宽度调整为小于800.如何实现?

I'm currently using this script to see if a user that's visiting my site has a screen width smaller than 800. The problem I have is that I also want the alert to be triggered when the user adjusts their screen width to be smaller than 800. How could this be achieved?

此刻脚本仅在最大屏幕宽度小于800时显示警报.

At the moment the script only displays the alert when the maximized screen width is lower than 800.

例如,当用户的宽度为1000,然后将其浏览器的宽度缩小为720时,我希望触发此消息.

For example, I would like this message triggered when the user has a width of say 1000 but then shrinks their browser width to 720.

  if (screen.width <= 800) {
    window.alert("screen smaller than 800");
  }

推荐答案

您需要:

window.addEventListener('resize', function() {
  if (window.innerWidth <= 800) {
    window.alert("screen smaller than 800");
  }
}, true);

这篇关于screen.width不检查窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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