-
-
Save riix/a1be663505136e1f40f650e2ad1acb0a to your computer and use it in GitHub Desktop.
onVisible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* function $.fn.onVisible runs callback function once the specified element is visible. | |
* callback: A function to execute at the time when the element is visible. | |
* example: $(selector).onVisible(callback); | |
*/ | |
(function($) { | |
$.fn.onVisible = function(callback) { | |
var self = this; | |
var selector = this.selector; | |
if (self.is(":visible")) { | |
callback.call(self); | |
} else { | |
timer = setInterval(function() { | |
if ($(selector).is(":visible")) { | |
callback.call($(selector)); | |
clearInterval(timer); | |
} | |
}, 50); | |
} | |
} | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment