我有一個小插件,用於根據幾個變量因子設置元素的高度。在頁面加載時,我想要延遲以防止高度被設置爲幾秒鐘。我知道延遲只適用於效果,有沒有辦法將我的插件註冊爲效果,還是需要以另一種方式進行操作?延遲()使用插件
慾望啓動代碼:
$(".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);
我可以添加到我的插件代碼?如果是這樣,任何指針如何 –
@MildFuzz:當然可以。就這樣放在那裏。 – jAndy
我只是在插件的動畫周圍封裝了隊列方法,並且延遲(外部觸發)看起來很好。謝謝!! –