/*
*
* Facebox also has a bunch of other hooks:
*
* loading.facebox
* beforeReveal.facebox
* reveal.facebox (aliased as 'afterReveal.facebox')
* init.facebox
* afterClose.facebox
*
*/我使用的是Facebox。在源代码中我找到了一些钩子,但我只能找到一行使用“beforeReveal”的代码:$(document).trigger('beforeReveal.facebox')。我找不到它在哪里定义的。所以我想知道它是如何工作的。希望能得到一些帮助。非常感谢!
发布于 2012-08-07 17:12:11
这些只是您可以订阅的自定义事件(例如,click是预定义的事件):
$(document).on('beforeReveal.facebox', function() {
// This code here is now executed every time before the facebox is revealed,
// because Facebox triggers this event.
});在文档中阅读更多内容:http://api.jquery.com/trigger/
发布于 2012-08-23 04:23:20
要澄清的是,这些触发器实际上并不调用facebox.js源代码中定义的函数。它们只是触发事件的触发器,不管有没有什么东西可以处理它。但是,如果您在javascript中定义了这些函数,它们将在facebox事件发生时被调用。
例如,如果您想要响应afterReveal.facebox (或beforeReveal),只需在您的javascript就绪函数中添加以下行,该函数应该位于您的文档头部分中。
$(document).ready (function() {
//initialize facebox
$('a[rel*=facebox]').facebox();
//create a response to the 'close.facebox' event
$(document).bind('close.facebox', function() {
//some function on close if you desire
});
//Create a response to the the 'afterReveal.facebox' event
$(document).bind('afterReveal.facebox', function() {
//Add your functionality here
$('textarea').autogrow();
return true;
});
});https://stackoverflow.com/questions/11842657
复制相似问题