element become visible

Possible Duplicate:
jQuery event to trigger action when a div is made visible

How can I run some my code when element, wich was loaded by ajax, become visible("display" is switching from "none" to "block")? Well, I need some event like

$('#element').live('show', function(){
// CODE
});

Or event that watching for deleting/adding some class to element


The problem was solved by using jquery-appear plugin

https://github.com/morr/jquery.appear


There's nothing built-in jQuery that allows you to achieve that. You may take a look at the livequery plugin. For example:

$('#element').livequery(function() {
    // CODE
});

When an element with id="element" is added to the DOM the callback should be executed.


Run a check every 1 second. If the #element exists and is visible then clear(stop) the interval and execute your code.

var checkVisible = setInterval(function(){

    // if element doesn't exist or isn't visible then end
    if(!$('#element').length || !$('#element').is(':visible'))
        return;

    // if element does exist and is visible then stop the interval and run code

    clearInterval(checkVisible);

    // place your code here to run when the element becomes visible

},1000);

Inevitably you have some jQuery event callback which shows the element; in those event callbacks you should place your 'when element is visible' run code.

链接地址: http://www.djcxy.com/p/83376.html

上一篇: 当div滚动到时运行javascript函数

下一篇: 元素变得可见