Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
构建jQueryUI小部件,如何创建回调_Jquery_Jquery Ui_Jquery Plugins - Fatal编程技术网

构建jQueryUI小部件,如何创建回调

构建jQueryUI小部件,如何创建回调,jquery,jquery-ui,jquery-plugins,Jquery,Jquery Ui,Jquery Plugins,我正在创建一个计时器小部件。现在我想在计时器启动时添加一个回调。 这是小部件的代码 (function($, undefined) { var timer = null; var timervalue = [0, 0, 0, 0, 0, 0, 0, 0, 1]; $.widget('ui.timer', { options: { showDays: null, showHours: null,

我正在创建一个计时器小部件。现在我想在计时器启动时添加一个回调。 这是小部件的代码

(function($, undefined) {
    var timer = null;
    var timervalue = [0, 0, 0, 0, 0, 0, 0, 0, 1];
    $.widget('ui.timer', {

        options: {
            showDays: null,
            showHours: null,
            showMinutes: null,
            showSeconds: null,
            separator: ':',
            showLabels: null,
            labels: ['Days', 'Hours', 'Minutes', 'Seconds'],
            isReverseCounter: true,
            getTimer: null,
            onStart: null
        },
        _create: function() {
            console.log($.ui.timer);
            $(this.element).bind('onStart', function(event, ui) {

            });

            $(this.element).width(0);
            $(this.element).addClass('ui-widget ui-widget-header ui-timer');
            if(this.options.showDays) {
                $('<div class="ui-widget ui-widget-content ui-timer-content">0</div>').appendTo(this.element);
                $('<div class="ui-widget ui-widget-content ui-timer-content">0</div>').appendTo(this.element);
                $('<div class="ui-widget ui-widget-content ui-timer-content">0</div>').appendTo(this.element);
                $(this.element).width($(this.element).width() + 198);
            }
            if(this.options.showHours) {
                if(this.options.showDays) {
                    $('<div class="ui-timer-separator-container"><label class="ui-timer-separator">' + this.options.separator + '</label></div>').appendTo(this.element);
                }
                $('<div class="ui-widget ui-widget-content ui-timer-content">0</div>').appendTo(this.element);
                $('<div class="ui-widget ui-widget-content ui-timer-content">0</div>').appendTo(this.element);
                $(this.element).width($(this.element).width() + 132);
            }
            if(this.options.showMinutes) {
                if(this.options.showHours) {
                    $('<div class="ui-timer-separator-container"><label class="ui-timer-separator">' + this.options.separator + '</label></div>').appendTo(this.element);
                }
                $('<div class="ui-widget ui-widget-content ui-timer-content">0</div>').appendTo(this.element);
                $('<div class="ui-widget ui-widget-content ui-timer-content">0</div>').appendTo(this.element);
                $(this.element).width($(this.element).width() + 132);
            }
            if(this.options.showSeconds) {
                if(this.options.showMinutes) {
                    $('<div class="ui-timer-separator-container"><label class="ui-timer-separator">' + this.options.separator + '</label></div>').appendTo(this.element);
                }
                $('<div class="ui-widget ui-widget-content ui-timer-content">0</div>').appendTo(this.element);
                $('<div class="ui-widget ui-widget-content ui-timer-content">0</div>').appendTo(this.element);
                $(this.element).width($(this.element).width() + 132);
            }
            if(this.options.showLabels) {
                $('<div class="ui-timer-labelPanel"></div>').appendTo(this.element);
                var labelPanel = $(this.element).find('.ui-timer-labelPanel');
                if(this.options.showDays) {
                    $('<label class="ui-timer-label">' + this.options.labels[0] + '</label>').width(176).appendTo(labelPanel);
                }
                if(this.options.showHours) {
                    $('<label class="ui-timer-label" style="margin-left:20px;">' + this.options.labels[1] + '</label>').width(112).appendTo(labelPanel);
                }
                if(this.options.showMinutes) {
                    $('<label class="ui-timer-label">' + this.options.labels[2] + '</label>').appendTo(labelPanel);
                }
                if(this.options.showSeconds) {
                    $('<label class="ui-timer-label">' + this.options.labels[3] + '</label>').appendTo(labelPanel);
                }
            }
        },
        _init: function() {
        },
        _start: function() {
            $(this.element).trigger('onStart',{ date: new Date()});
            if(this.options.isReverseCounter) {

            }
            else {
                setInterval(function() {
                    $('.ui-timer-separator').fadeOut();
                    $('.ui-timer-separator').fadeIn();
                }, 1000);
                timer = setInterval(function() {
                    $('.ui-timer-content:last').text(timervalue[5]);
                    $($('.ui-timer-content')[$('.ui-timer-content').length - 2]).text(timervalue[4]);
                    $($('.ui-timer-content')[$('.ui-timer-content').length - 3]).text(timervalue[3]);
                    $($('.ui-timer-content')[$('.ui-timer-content').length - 4]).text(timervalue[2]);
                    $($('.ui-timer-content')[$('.ui-timer-content').length - 5]).text(timervalue[1]);
                    $($('.ui-timer-content')[$('.ui-timer-content').length - 6]).text(timervalue[0]);
                    timervalue[5] += 1;
                    if(timervalue[5] == 10) {
                        timervalue[5] = 0;
                        timervalue[4]++;
                        if(timervalue[4] == 6) {
                            timervalue[4] = 0;
                            timervalue[3]++;
                            if(timervalue[3] == 10) {
                                timervalue[3] = 0;
                                timervalue[2]++;
                                if(timervalue[2] == 6) {
                                    timervalue[2] = 0;
                                    timervalue[1]++;
                                    if(timervalue[1] == 10) {
                                        timervalue[1] = 0;
                                        timervalue[0]++;
                                        if(timervalue[1] == 4 && timervalue[2] == 2) {
                                            timervalue[0] = 0;
                                            timervalue[1] = 0;
                                            timervalue[2] = 0;
                                            timervalue[3] = 0;
                                            timervalue[4] = 0;
                                            timervalue[5] = 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }, 1000);
            }
        },
        widget: function() {

        },
        destroy: function() {
        },
        _setOption: function(key, value) {
        },
        refresh: function() {

        },
        start: function() {
            this._start();
        },
        stop: function() {
            clearTimeout(timer);
            $('.ui-timer-separator').stop();
        },
        reset: function() {
        },
        pause: function() {
        }
    });
})(jQuery);
(函数($,未定义){
var定时器=null;
var timervalue=[0,0,0,0,0,0,0,0,1];
$.widget('ui.timer'{
选项:{
showDays:null,
显示时间:空,
showments:null,
showSeconds:null,
分隔符:':',
showLabels:null,
标签:[“天”、“小时”、“分钟”、“秒”],
伊斯雷弗塞克特:是的,
getTimer:null,
onStart:null
},
_创建:函数(){
console.log($.ui.timer);
$(this.element).bind('onStart',函数(事件,ui){
});
$(this.element).width(0);
$(this.element).addClass('ui-widget-ui-widget头ui-timer');
if(this.options.showDays){
$('0').appendTo(this.element);
$('0').appendTo(this.element);
$('0').appendTo(this.element);
$(this.element).width($(this.element.width()+198);
}
if(this.options.showHours){
if(this.options.showDays){
$(''+this.options.separator+'').appendTo(this.element);
}
$('0').appendTo(this.element);
$('0').appendTo(this.element);
$(this.element).width($(this.element.width()+132);
}
if(this.options.showMinutes){
if(this.options.showHours){
$(''+this.options.separator+'').appendTo(this.element);
}
$('0').appendTo(this.element);
$('0').appendTo(this.element);
$(this.element).width($(this.element.width()+132);
}
if(this.options.showSeconds){
if(this.options.showMinutes){
$(''+this.options.separator+'').appendTo(this.element);
}
$('0').appendTo(this.element);
$('0').appendTo(this.element);
$(this.element).width($(this.element.width()+132);
}
if(this.options.showLabels){
$('').appendTo(this.element);
var labelPanel=$(this.element).find('.ui timer labelPanel');
if(this.options.showDays){
$(''+this.options.labels[0]+'').width(176).appendTo(labelPanel);
}
if(this.options.showHours){
$(''+this.options.labels[1]+'').width(112).appendTo(labelPanel);
}
if(this.options.showMinutes){
$(''+this.options.labels[2]+'').appendTo(labelPanel);
}
if(this.options.showSeconds){
$(''+this.options.labels[3]+'').appendTo(labelPanel);
}
}
},
_init:function(){
},
_开始:函数(){
$(this.element).trigger('onStart',{date:new date()});
if(this.options.isReverseCounter){
}
否则{
setInterval(函数(){
$('.ui计时器分隔符').fadeOut();
$('.ui计时器分隔符').fadeIn();
}, 1000);
计时器=设置间隔(函数(){
$('.ui timer content:last').text(timervalue[5]);
$($('.ui timer content')[$('.ui timer content').length-2]).text(timer值[4]);
$($('.ui timer content')[$('.ui timer content').length-3]).text(timer值[3]);
$($('.ui timer content')[$('.ui timer content').length-4]).text(timer值[2]);
$($('.ui timer content')[$('.ui timer content').length-5]).text(timer值[1]);
$($('.ui timer content')[$('.ui timer content').length-6]).text(timer值[0]);
timervalue[5]+=1;
if(timervalue[5]==10){
timervalue[5]=0;
时间值[4]++;
if(timervalue[4]==6){
timervalue[4]=0;
时间值[3]++;
if(timervalue[3]==10){
timervalue[3]=0;
时间值[2]++;
if(timervalue[2]==6){
timervalue[2]=0;
时间值[1]++;
if(timervalue[1]==10){
timervalue[1]=0;
时间值[0]++;
if(timervalue[1]==4&&timervalue[2]==2){
timervalue[0]=0;
timervalue[1]=0;
timervalue[2]=0;
timervalue[3]=0;
timervalue[4]=0;
timervalue[5]=0;
}
}
}
}
}
}
}, 1000);
}
},
小部件:函数(){
},
销毁:函数(){
},
_设置选项:功能(键、值){
},
刷新:函数(){
},
开始:函数(){
这个;
},
停止:函数(){
清除超时(计时器);
$('.ui计时器分隔符').stop();
},
重置:函数(){
},
this._trigger('start', this);