如何检测滚动框(html元素)是否可滚动 [英] How can you detect if a scroll box (html element) is scrollable

查看:147
本文介绍了如何检测滚动框(html元素)是否可滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的问题,但我想知道是否有一种可能的方式来检测具有multiple属性的选择框是否通过jQuery或JavaScript可滚动(即列表中足够的元素以要求滚动选择框)?



问候,



Mary

解决您需要比较元素的可见 height() scrollHeight ,像这样:

  if($('#foo')。height()< $('#foo') [0] .scrollHeight){
alert('scrollable');
}

示例小提琴


Weird question, but I would like to know if there is a possible way of detecting if a select box with the multiple attribute is scrollable (i.e. enough elements in list to require the scrolling of the select box) via jQuery or javascript ?

Regards,

Mary

解决方案

You need to compare the visible height() of the element to the scrollHeight, something like this:

if ($('#foo').height() < $('#foo')[0].scrollHeight) {
    alert('scrollable');
}

Example fiddle

这篇关于如何检测滚动框(html元素)是否可滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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