当 div 从可见状态变为隐藏时调用 Javascript 函数
我想在 div 从“visibilty:hidden”变为“visibility:none;”时调用 Javascript 函数
另请注意,我无法控制转换 div 的此样式属性的脚本。我只是想参与其中。有什么可能性吗?或者像 onFocus()
等?
更新:我不想使用 JQuery 或其他框架。是否可以?
I want to call a Javascript function when a div is turned from "visibilty : hidden" to "visibility : none;"
Also note that I don't have control over the script which turns this style property of the div. I just want to hook into this. Any possibilities? Or like onFocus()
etc?
UPDATE : I do not want to use JQuery or other frameworks. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 mootools 中,您可以创建自定义事件。但是,我会这样做:
并在切换对象可见性的任何代码中添加对对象的“triggerMyEvent”方法的调用。
In mootools you can create custom events. However, I would do something like this:
And add a call to the object's 'triggerMyEvent' method in whatever code switches the object's visibility.
IE 中有一个
propertychange
事件,它响应元素属性的更改,包括其style
对象的属性。但是,这仅适用于直接在元素的style
对象上设置的属性,不适用于间接影响元素样式的 CSS 更改(例如更改元素的父元素的类)。在其他浏览器中使用 DOMAttrModified 的工作方式类似,并且具有相同的缺点,因此这可能不适合您。There's the
propertychange
event in IE that responds to changes in an element's properties, including properties of itsstyle
object. However, this only works on properties set directly on the element'sstyle
object and doesn't work for CSS changes (e.g. changing the class of the element's parent element) that indirectly affect the element's style. Using the DOMAttrModified in other browsers will work similarly and has the same shortcomings, so this may not be workable for you.