这是我的代码:
$('#details').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() {
$(tag).hide();
});
Run Code Online (Sandbox Code Playgroud)
当我"mouseout"时,变量"tag"不会隐藏.
JSFiddle:http://jsfiddle.net/79kLc/
谢谢!
学习关于 scope
var tag = 'div.cds'
$('#details').hover(function() {
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() {
$(tag).hide();
});
Run Code Online (Sandbox Code Playgroud)
该tag变量在第二个函数的范围内不存在.所以我加入tag了全球范围.它现在应该工作了.
| 归档时间: |
|
| 查看次数: |
61 次 |
| 最近记录: |