使delay()与插件一起工作
Making delay() work with a plugin
我有一个小插件,用于根据几个可变因素设置元素的高度。在页面加载时,我想要一个延迟,以防止在几秒钟内设置高度。我知道延迟只对效果有效,有没有办法把我的插件注册为效果,或者我需要用另一种方式吗?
所需发射代码:
$(".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编写自己的延迟插件,使用一个伪方法,这样你就可以链接你的事件。
相关文章:
- 高亮显示与数组字符串一起使用时文本插件中断
- 将RequireJs与自定义JS插件一起使用
- 如何使Jquery插件与emberJS一起工作
- 如何加载JSON数据以将其与select2插件一起使用
- jQuery timepicker不想与日期选择器插件一起显示
- 使jQuery选择的插件与动态添加的下拉列表一起使用
- 将 NPAPI 插件与节点一起使用
- 如何将 jQuery 和 jQuery 插件与 PrimeFaces 一起使用
- 不确定如何将gridster.serialize()与Gridster jQuery插件一起使用
- 如何使最大宽度和高度与Jquery ImgViewer插件一起工作
- CSS代码应该与插件一起使用还是在子主题中使用
- javascript和jquery插件一起使用document.ready函数
- Angular自定义指令不能与外部javascript插件一起工作
- 最有效的使用Jquery分页的方法&历史插件一起
- 是否有任何javascript模板库可以与webpack's i18n插件一起工作
- 如何与zclip插件一起使用live方法
- 使delay()与插件一起工作
- 将JSON数据与jQuery highcharts插件一起使用
- 将 JQuery ON 与动态元素插件一起使用
- 为什么这个Greasemonkey脚本不能与这个jQuery插件一起工作?