jQuery click off element event

后端 未结 15 1087
無奈伤痛
無奈伤痛 2020-12-13 00:25

I have a floating div that gets displayed, and I want it to be hidden when the user clicks off the div. This would be similar to the .hover() function callback when hoverin

15条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 00:30

    Here's a full-fledged event-driven approach

    • Custom events handle the "summoning" and "dismissing" of the layer as to not step on the toes of other click-based events
    • document.body listens to for a dismiss event only when the layer in question is actually visible

    Zee code:

    
    
    
    test
    
    
    
    
    
    
    
    
    
    
    test
    Show div

    It's a lot of code I know, but here just to show a different approach.

提交回复
热议问题