什么时候元素可见的事件监听器? [英] Event listener for when element becomes visible?

查看:49
本文介绍了什么时候元素可见的事件监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个将包含在页面中的工具栏.将要包含在其中的div将默认为 display:none .有什么方法可以在我的工具栏上放置一个事件侦听器,以便在它可见时进行侦听,以便可以对其进行初始化?还是我必须从包含页面的变量中传递一个变量?

I am building a toolbar that is going to be included into a page. the div it is going to be included in will default to display:none. Is there a way i can put an event listener on my toolbar to listen for when it becomes visible so it can initialize? or will I have to pass it a variable from the containing page?

谢谢

推荐答案

Javascript 事件处理 User Interaction ,如果您的代码组织得足够好,您应该可以调用可见性在同一位置的初始化函数(即,您不应该在许多地方更改myElement.style.display,而是调用执行此操作的函数/方法以及您可能想要的其他任何方法).

Javascript events deal with User Interaction, if your code is organised enough you should be able to call the initialising function in the same place where the visibility changes (i.e. you shouldn't change myElement.style.display on many places, instead, call a function/method that does this and anything else you might want).

这篇关于什么时候元素可见的事件监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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