jQuery event to trigger action when a div is made visible

后端 未结 22 2499
你的背包
你的背包 2020-11-22 12:03

I\'m using jQuery in my site and I would like to trigger certain actions when a certain div is made visible.

Is it possible to attach some sort of \"isvisible\" even

22条回答
  •  -上瘾入骨i
    2020-11-22 12:39

    There is a jQuery plugin available for watching change in DOM attributes,

    https://github.com/darcyclarke/jQuery-Watch-Plugin

    The plugin wraps All you need do is bind MutationObserver

    You can then use it to watch the div using:

    $("#selector").watch('css', function() {
        console.log("Visibility: " + this.style.display == 'none'?'hidden':'shown'));
        //or any random events
    });
    

提交回复
热议问题