왜 이것이 실행되지 않습니까?jQuery 맞춤 이벤트
$('#nav').bind('app:event', function (event, status) {
console.log([event, status]);
});
이 때 : 플러그인 내에서
$(this).trigger('app:event', [options]);
:
$(document).bind('app:event', function (event, status) {
console.log([event, status]);
});
이벤트 트리거가 사용 중이다.
이 전체 블록 :
/* App.js */
$(function ($) {
// UI Panels
$('#panels').panels({
controls: '#nav a'
});
$('#nav').bind('app:event', function (event, status) {
console.log([event, status]);
});
});
/**
* Plugin dir
*/
(function($) {
// Interface
$.fn.panels = function (options) {
var settings = {}, current;
if (options) {
$.extend(settings, options);
}
// Setup
$('.panel', this).hide();
$('.panel:first', this).slideDown('slow');
return this.each(function() {
var self = $(this);
$(settings.controls).click(function() {
// Get reference
current = this.href.substring(this.href.indexOf('#') + 1);
// Hide all
$('.panel', self).hide();
// Show current
$('#'+ current)
.publish({
'panelReady': current
})
.slideDown();
return false;
});
});
};
// Publish event
$.fn.publish = function (options) {
var settings = {
origin: this
};
if (options) {
$.extend(settings, options);
}
return this.each(function() {
$(this).trigger('app:event', [options]);
});
};
}(jQuery));
나는 #ID 주위 $(document).ready()
을 넣어 이벤트에
$ ('# nav') 주변에 $ (document) .ready()가 있습니다. bind()? – powtac