JS:元素变得可见时的事件监听器? [英] JS: event listener for when element becomes visible?

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

问题描述

我正在构建一个将包含在页面中的工具栏。它将被包含在内的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 事件处理用户交互,如果您的代码足够有条理,您应该能够在可见性发生变化的同一个地方调用初始化函数(即你不应该在很多地方改变 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).

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

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