What exactly acts as a trigger for a custom event in Javascript

I've been reading about custom events and looked at some examples. Perhaps I am misunderstanding what custom events are and how they are triggered and would appreciate some help. Example Problem To trigger an event when the background colour of a div changes from one colour to another. Situation A) The colour changes as result of user activity detectable from within the script, eg by onclick, onmouseover, onkeypress then I would set up a listener for these events and respond accordingly. This I understand how to do. Situation B) The colour changes as the result of user activity not detectable from within the script, eg a new theme applied to the page, then am I correct in thinking the following are necessary? 1. I would need to create a custom event for colour change. 2. Add a listener for the event to the appropriate DIV 3. The listener would need to poll the DIV at intervals to check for colour changes Really its step 3 I am not clear about. If you are not polling the DIV how does the event colour change trigger an event? In other words how does the script know that a colour change has taken place?
what is “new theme being applied”? this is still custom code someone written, and that code may trigger the desired event.

以上就是What exactly acts as a trigger for a custom event in Javascript的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏