检测窗口垂直滚动条何时出现 [英] Detect when window vertical scrollbar appears

查看:261
本文介绍了检测窗口垂直滚动条何时出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个简单可靠的检测窗口垂直滚动条出现/消失的解决方案?

Is there a simple and reliable solution for detecting window vertical scrollbar appears/disappears?

window.onresize 在JavaScript DOM操作页面变得足够高以显示滚动条之后,不会触发。

window.onresize isn't triggered when after JavaScript DOM manipulation page becomes high enough for appearing scrollbar.

在这个非常相似的帖子中检测页面是否有垂直滚动条描述了如何检测滚动条是否存在的解决方案,但我需要知道究竟是什么时候出现。

In this very similar post Detect if a page has a vertical scrollbar described solution how to detect whether scrollbar is present or not, but I need to know when exactly it appears.

推荐答案

Window.onresize 不起作用,因为窗口没有调整大小。

Window.onresize won't work, because the window isn't resizing.

body.onresize 将无效,因为调整大小仅适用于Windows和框架。

body.onresize won't work, as resize is implemented only for windows and frames.

此问题 处理同一问题。顶级回答者有一些有趣的想法,虽然不是简单的,或跨浏览器。

This question deals with the same issue. The top answerer has some interesting ideas, though none simple, or cross-browser.

我认为Rick Strahl基于Jquery的方法是你能得到的最好的: 监控JavaScript中的Html元素CSS更改 浏览器的监视功能(如果可用)或计时器(如果不可用)。后者不是非常有利于资源,但似乎没有办法解决它。

I think this Jquery based approach by Rick Strahl is the best you can get: Monitoring Html Element CSS Changes in JavaScript it uses the browser's "watch" functions if available, or a timer if not. The latter is not very resource friendly but there seems to be no way around it.

一旦调整大小,如何告诉滚动条的好方法/ code>解决的问题是 这个问题 顺便说一句,以防您在提问时没有提到那个。

A good way how to tell the scrollbar once the resize thing is resolved is in this question by the way, just in case you aren't referring to that one in your question.

这篇关于检测窗口垂直滚动条何时出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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