【发布时间】:2011-08-31 11:09:18
【问题描述】:
我对命名空间和全局变量非常陌生。我目前有这个代码:
$('#formats1').hover(function() {
var tag = 'div.cds';
var offset = $(this).position();
var width = $(tag).outerWidth();
var height = $(tag).outerHeight();
$(tag).show();
$(tag).css('left', offset.left - width + 'px');
$(tag).css('top', offset.top - height + 'px');
}, function() {
$("div.cds").hide();
});
$('#formats2').hover(function() {
var tag = 'div.lp';
var offset = $(this).position();
var width = $(tag).outerWidth();
var height = $(tag).outerHeight();
$(tag).show();
$(tag).css('left', offset.left - width + 'px');
$(tag).css('top', offset.top - height + 'px');
}, function() {
$("div.lp").hide();
});
这在此刻对各种 div 重复了很多次。
我觉得这将是一个合并命名空间和全局变量的好机会,但我不确定如何去做。有什么想法吗?
谢谢!
【问题讨论】:
标签: jquery variables namespaces global