什么是面框“钩子”

What's the facebox 'hooks'

本文关键字:钩子 什么      更新时间:2023-09-26
/*
* 
*  Facebox also has a bunch of other hooks:
*
*    loading.facebox
*    beforeReveal.facebox
*    reveal.facebox (aliased as 'afterReveal.facebox')
*    init.facebox
*    afterClose.facebox
*
*/

我正在使用面框。在源代码中,我找到了一些钩子,但我只能找到一行使用"beforeReveal":$(document).trigger('beforeReveal.facebox') .我找不到它的定义位置。所以我想知道它是如何工作的。希望得到一些帮助。非常感谢!

这些只是自定义事件(例如 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/

澄清一下,这些触发器实际上并不是调用 facebox 中定义的函数.js源代码。 它们只是触发事件的触发器,无论是否有东西来处理它。 但是,如果您在 javascript 中定义这些函数,则在 facebox 事件发生时将调用它们。

例如,如果你想响应afterReveal.facebox(或之前Reveal(,只需在你的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;
      });
});