简体   繁体   English

javascript是否可以检测滚动条何时不可用(即在移动浏览器上)?

[英]Can javascript detect when scrollbars are unavailable (i.e. on mobile browsers)?

I've got a javascript-based Scrolling Widget Thingy™. 我有一个基于JavaScript的Scrolling Widget Thingy™。 One of the things it does is create a fixed height div and gives it overflow: auto . 它要做的一件事是创建一个固定的高度div并给它overflow: auto

Alas on mobile Safari (and other mobile browsers) overflow: auto; mobile在移动Safari(和其他移动浏览器)上overflow: auto; doesn't show a scrollbar. 不显示滚动条。 Any content below "the fold" can only be found by accident. 折痕以下的任何内容只能偶然发现。

Is there a way to detect this in javascript, without resorting to browser detection? 有没有办法在使用浏览器检测的情况下用javascript检测到这一点? eg 例如

if (there is a scrollbar) {
    /* give me a fixed height and a scrollbar */
} else {
    /* Do something more suited to this situation */
}

I can only think of resorting to dirty tricks: 我只能想到诉诸于肮脏的把戏:

  1. Create 50x50 box 创建50x50框
  2. Set box to overflow: auto 设置框overflow: auto
  3. Flood box with text 文字框
  4. Read box inner size: if 50x50, something went wrong 读取包装盒的内部尺寸:如果是50x50,则出了点问题
  5. Store result in variable and destroy box 将结果存储在变量中并销毁框

... given that there's actually a way to measure the inner size, scrollbar excluded. ...鉴于实际上有一种测量内部尺寸的方法,不包括滚动条。

It's a scary algorithm anyway, hundreds of things can go wrong... Consider it just an idea. 无论如何,这是一个令人恐惧的算法,成百上千的事情可能会出错……考虑一下这只是一个想法。

暂无
暂无

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

相关问题 如何在不轮询的情况下检测某个DIV的大小已更改? 即,我想要调整大小的事件监听器? - How can I detect when a certain DIV has changed size without polling? I.e., I want a resize event listener? 如何在不检查HTTP标头的情况下检测移动浏览器? - How can I detect mobile browsers without checking HTTP headers? 是什么导致IE在其他浏览器执行时无法验证(jquery) - What is causing I.E. to not validate (jquery) when other browsers do JavaScript:检测移动嵌入式浏览器(强制门户) - JavaScript: Detect Mobile Embedded Browsers (Captive Portal) Javascript:有没有办法检测用户滚动,但不能通过代码滚动(即 scrollLeft 等)? - Javascript : is there a way to detect user scrolling, but not scrolling done by code (i.e. scrollLeft etc)? 使用 Javascript 在 Mobile Safari / iPhone 中防止鼠标模拟事件(即点击) - Preventing mouse emulation events (i.e. click) from touch events in Mobile Safari / iPhone using Javascript 如何检测图像何时在浏览器中完成渲染(即绘制)? - How to detect when an image has finished rendering in the browser (i.e. painted)? Javascript函数就像对象,即“$”可以用作函数,例如$()以及对象$ - Javascript Function like Objects i.e. “$” can be used as a function e.g. $() as well as an object $ JavaScript提示输入密码(即*******) - javascript prompt for password (i.e. *******) 使用Blazor(即WebAssembly)+ JavaScript - Using Blazor (i.e. WebAssembly) + javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM