onscroll for div [英] onscroll for div

查看:131
本文介绍了onscroll for div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

div元素没有 onscroll 事件处理程序?
我的页面上的行为似乎并没有显示识别div onscroll 事件处理程序。

 < div id ='bd'onscroll ='alert(Scroll Called);'>< / div> 

另外,

Do滚动事件会滚动到窗口滚动事件,如每个DOM事件冒泡?

解决方案根据您使用的HTML版本,您可以使用 onwheel 事件,而不是。



onscroll 是真的:


  1. div有溢出:auto overflow:scroll overflow-y:scroll


  2. 鼠标移动实际上会导致滚动条滚动。

所以 onscroll 事件并不适合检测一般的鼠标滚轮移动。

请注意 c> onwheel 事件在HTML 5中是新的。根据w3schools ,它很宽虽然支持。


Does a div element not have an onscroll event handler? The behaviour on my page doesn't seem to indicate the div onscroll event handler is recognized.

<div id='bd' onscroll='alert("Scroll Called");'></div>

Also,
Do div scroll events roll up to window scroll events, as per DOM event bubbling ?

解决方案

Depending on which version of HTML you're using, you could use the onwheel event, instead.

The onscroll event works only if all the following are true:

  1. The div has overflow: auto, overflow: scroll, overflow-y: scroll, etc.
  2. The div currently has a visible scrollbar that can scroll.
  3. The mouse movement actually causes the scrollbar to scroll.

So the onscroll event is not really suited for detecting general mouse wheel movement.

Please note that the onwheel event is new in HTML 5. According to w3schools, it is pretty widely supported, though.

这篇关于onscroll for div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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