jQuery delayed events.

February 1, 2013

onDelay is simple jquery plugin that trigger events with delay.

/**
 * Trigger event delayed.
 * @author Ivan Gospodinow
 * @site http://www.ivangospodinow.com
 * @mail ivangospodinow@gmail.com
 * @date 01.02.2013
 */
(function($) {
    $.fn.onDelay = function(type, delay, funct) {
        delay = undefined === delay ? 500 : parseInt(delay);
        var timeOut;
        $(this).unbind(type)[type](function(e,x,y,z) {
            clearTimeout(timeOut);
            var self = this;
            timeOut = setTimeout(function(){
                funct.call(self,e,x,y,z);
            },delay);
        });
    };
})(jQuery);

How to use it ?

(function($) {
	$(window).onDelay('click', 2000, function(e) {
		console.log('Sorry , I am late.');
	})
})(jQuery);

UPDATED - Now supports $(this) in chield function.
Suggestions or problems ?

Write a comment.

tags: , , ,
posted in jQuery, js, Plugins by Ivan Gospodinow

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment

 
 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org