使delay()与插件一起使用

| 我有一个小插件,可根据几个可变因素来设置元素的高度。在页面加载时,我希望有一个延迟,以防止在几秒钟内设置高度。我知道延迟仅在效果上起作用,有没有办法将我的插件注册为效果,还是我需要以其他方式做到这一点? 需求启动代码:
$(\".app_advert\").delay(10000).set_height(2000);
插件代码:
       //SetHeight plugin
    (function($){
        $.fn.extend({
            set_height: function(time, callback){
                    scroll = $(window).scrollTop();

                    win_height = $(window).height();
                    document_height = $(document).height();


                    footer_height = $(\'#footer\').height();
                    footer_offset = (document_height-(win_height+scroll));
                    footer_remainder = footer_height-footer_offset;

                return this.each(function(){
                    var x = $(this);

                    if(footer_height-footer_offset<=0){
                        height = 0;
                    } else {
                        height = footer_height-footer_offset;
                    }
                    $(x).stop(true, false).animate({bottom: height}, time, function(){
                        if (callback && typeof callback == \'function\') { // make sure the callback is a function
                                callback.call(this); // brings the scope to the callback
                            }

                    });
                });
            }
        });

})(jQuery);
    
已邀请:
        您将需要手动调用jQuerys
.queue()
。看起来像;
$(\".app_advert\").delay(10000).queue(function() {
    $(this).set_height(2000);
    $(this).dequeue();
});
您甚至可以在该构造上链接更多排队的方法。注意,默认情况下,所有
fx methods
都将排队,以等待要应用到当前包装集的任何其他方法,并调用另一个
.queue()
。 阅读:http://api.jquery.com/queue     
        如何在插件中使用setTimeout。甚至更好的方法是使用伪方法使用setTimeout编写自己的延迟插件,以便可以链接事件。     

要回复问题请先登录注册