我已经安装了运行良好的 Slimbox。
然而,Slimbox 作者已经封装了所有 Slimbox 代码,并在设置一些全局变量后,在 var 中初始化 DOM。
var Slimbox = (function() {
// Global variables, accessible to Slimbox only
var win = window, ie6 = Browser.ie6, options, images, activeImage = -1, activeURL, prevImage, nextImage, compatibleOverlay, middle, centerWidth, centerHeight,
// Preload images
preload = {}, preloadPrev = new Image(), preloadNext = new Image(),
// DOM elements
overlay, center, image, sizer, prevLink, nextLink, bottomContainer, bottom, caption, number,
// Effects
fxOverlay, fxResize, fxImage, fxBottom;
// now initialize the DOM
window.addEvent('domready', function() {
// *************
// This is where the problem arises.
// I call ajax actions here, and some functions which are external to 'domready'
// *************
pageInit();
setupFormSubmit('product_bid', 'afterPlaceBid');
setupAjaxAction('delete_validate_id_link', 'afterDelete');
setupAjaxAction('move_validate_down_link', 'afterMoveValidate');
//etc...
});
// end the DOM function
function afterMoveValidate(){
}
function afterDelete() {
}
// all the Slimbox functions are here too...
etc..
//end the var Slimbox
})
问题是我的外部函数虽然仍在 var 中,但没有全局范围,而 Slimbox 函数却有。
这在没有 Slimbox 的情况下确实有效,我在其中初始化了 DOM 并具有外部函数。
任何人都可以提供想法/解释吗?
谢谢