Kha*_*eed 0 jquery-ui jquery-ui-tabs
我想让"jQuery UI TAB"闪烁(就像通知一样).我有不同的标签(收件箱|已发送|重要).我的计时器功能检查收件箱中是否有新消息,如果有,我希望收件箱选项卡开始闪烁/闪烁,除非它被点击打开.
尝试了不同的选项,如.effect(..),.tarbs(fx:{..}),但似乎没有任何工作:(
任何想法是否可能?
是的,这绝对是可能的.
为了给我一些练习,我blinker为你编写了一个jQuery 插件:
jQuery的:
(function($){
// **********************************
// ***** Start: Private Members *****
var pluginName = 'blinker';
var blinkMain = function(data){
var that = this;
this.css(data.settings.css_1);
clearTimeout(data.timeout);
data.timeout = setTimeout(function(){
that.css(data.settings.css_0);
}, data.settings.cycle * data.settings.ratio);
};
// ***** Fin: Private Members *****
// ********************************
// *********************************
// ***** Start: Public Methods *****
var methods = {
init : function(options) {
//"this" is a jquery object on which this plugin has been invoked.
return this.each(function(index){
var $this = $(this);
var data = $this.data(pluginName);
// If the plugin hasn't been initialized yet
if (!data){
var settings = {
css_0: {
color: $this.css('color'),
backgroundColor: $this.css('backgroundColor')
},
css_1: {
color: '#000',
backgroundColor: '#F90'
},
cycle: 2000,
ratio: 0.5
};
if(options) { $.extend(true, settings, options); }
$this.data(pluginName, {
target : $this,
settings: settings,
interval: null,
timeout: null,
blinking: false
});
}
});
},
start: function(){
return this.each(function(index){
var $this = $(this);
var data = $this.data(pluginName);
if(!data.blinking){
blinkMain.call($this, data);
data.interval = setInterval(function(){
blinkMain.call($this, data);
}, data.settings.cycle);
data.blinking = true;
}
});
},
stop: function(){
return this.each(function(index){
var $this = $(this);
var data = $this.data(pluginName);
clearInterval(data.interval);
clearTimeout(data.timeout);
data.blinking = false;
this.style = '';
});
}
};
// ***** Fin: Public Methods *****
// *******************************
// *****************************
// ***** Start: Supervisor *****
$.fn[pluginName] = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || !method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist in jQuery.' + pluginName );
}
};
// ***** Fin: Supervisor *****
// ***************************
})( jQuery );
Run Code Online (Sandbox Code Playgroud)
在这里看到它
插件和小提琴非常原始,因为我没有尝试与jQuery-ui-tabs集成.这可能很容易或很难,我不知道,但是提供每个标签可以通过类或id进行寻址,那么它应该不会太难.
您可能需要考虑的是在单击时停止闪烁选项卡.为此,您可能希望.blinker('stop')直接(使用.on('click')处理程序)或从适当的jQuery-ui-tabs回调调用该方法.
API
插件是用jQuery的首选模式编写的.它只在jQuery.fn命名空间中放入一个成员,.blinker(...)并将像标准的jQuery方法一样链接.
方法:
.blinker(options),或者.blinker()以最简单的形式调用.选项:属性图,用于确定闪光灯样式和时间:
通过省略css_0选项图,OFF状态由元素(在其他地方定义的自然CSS样式(通常在样式表中))确定.
默认值是硬编码为css_1.color,css_1.backgroundColor,cycle时间和ratio.不会以编程方式更改默认设置,因此对于不同的默认样式,需要编辑插件.
| 归档时间: |
|
| 查看次数: |
2510 次 |
| 最近记录: |