开发者

Hiding DIV if mouse not over, after delay?

tooltip = "#tooltip";

When adding marker to map I add a listener:

google.maps.event.addListener(marker, 'mouseout', function () {
                        hideWindow(tooltip);
                    });

Which goes to this:

function hideWindow(d开发者_StackOverflow社区iv) {
                var t = setTimeout("jQuery(div).hide()", 1000);
        }

Firebug states 'div' is not defined. Why?


You shouldn't use strings inside the setTimeout but a closure.

eg:

setTimeout(function(){
  jQuery(div).hide()
}, 1000)


It's not defined because you're using the string version of setTimeout so your variable div isn't in scope. This shouldn't be used if at all possible.

Try this instead:

function hideWindow(div) {
    var t = setTimeout(function() {
        jQuery(div).hide();
    }, 1000);
}

Alternatively, if you want to use jQuery animations you can put the delay directly in your event handler using .delay():

google.maps.event.addListener(marker, 'mouseout', function () {
    jQuery(tooltip).delay(1000).hide('fast');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜