我刚接手的活...有点乱,网站是wishmap.net.
问题是,如果你点Illinois Tech后,你能看到一个个的Pin在地图上,如果你把鼠标移动到那个pin上面去,就会有个信息框显示出来,可是问题是如果鼠标移走后,那个框还不会消失。我刚刚才粗略看了下代码,好像问题是原来的作者是使用timer去消除信息框,能不能用mosue moveout事件来做呢?因为我javascript也不是很熟,请高手指导下..谢谢!
function displayInfobox(e) {
            // make sure we clear any infoBox timer that may still be active
    stopInfoboxTimer(e);            // build or display the infoBox
            var pin = e.target;
            if (pin != null) {
                // Create the info box for the pushpin
                var boxData;
                $.ajax({
                    type: "POST",
                    url: "/Home/WishListItem",
                    data: "id=" + pin.getText() + "&mapItem=true",
                    async: false,
                    success: function (html) {
                        boxData = html;
                    }
                });                var location = pin.getLocation();
                var data = pins[pin.getText()];
                var options = {
                    htmlContent: boxData,
                    visible: true,
                    showPointer: true,
                    showCloseButton: true,
                    // offset the infobox enough to keep it from overlapping the pin.
                    offset: new Microsoft.Maps.Point(0, pin.getHeight()),  
                    zIndex: 999
                };
                // destroy the existing infobox, if any
                // In testing, I discovered not doing this results in the mouseleave
                // and mouseenter events not working after hiding and then reshowing the infobox.
                if (pinInfobox != null) {
                    map.entities.remove(pinInfobox);
                    if (Microsoft.Maps.Events.hasHandler(pinInfobox, 'mouseleave'))
                        Microsoft.Maps.Events.removeHandler(pinInfobox.mouseLeaveHandler);
                    if (Microsoft.Maps.Events.hasHandler(pinInfobox, 'mouseenter'))
                        Microsoft.Maps.Events.removeHandler(pinInfobox.mouseEnterHandler);
                    pinInfobox = null;
                }
                // create the infobox
                pinInfobox = new Microsoft.Maps.Infobox(location, options);
                // hide infobox on mouseleave
                pinInfobox.mouseLeaveHandler 
                    = Microsoft.Maps.Events.addHandler(pinInfobox, 'mouseleave', pinInfoboxMouseLeave);
                // stop the infobox hide timer on mouseenter
                pinInfobox.mouseEnterHandler 
                    = Microsoft.Maps.Events.addHandler(pinInfobox, 'mouseenter', pinInfoboxMouseEnter);
                // add it to the map.
                map.entities.push(pinInfobox);
            }
        }        function hideInfobox(e) {
            if (pinInfobox != null)
                pinInfobox.setOptions({ visible: false });
        }        // This function starts a count-down timer that will hide the infoBox when it fires.
        // This gives the user time to move the mouse over the infoBox, which disables the timer
        // before it can fire, thus allowing clickable content in the infobox.
        function startInfoboxTimer(e) {
            // start a count-down timer to hide the popup.
            // This gives the user time to mouse-over the popup to keep it open for clickable-content.
            if (pinInfobox.pinTimer != null) {
                clearTimeout(pinInfobox.pinTimer);
            }
            // give 300ms to get over the popup or it will disappear
            pinInfobox.pinTimer = setTimeout(timerTriggered, 300);
        }        // Clear the infoBox timer, if set, to keep it from firing.
        function stopInfoboxTimer(e) {
            if (pinInfobox != null && pinInfobox.pinTimer != null) {
                clearTimeout(pinInfobox.pinTimer);
            }
        } function pinInfoboxMouseLeave(e) {
            hideInfobox(e);
        }
        function pinInfoboxMouseEnter(e) {
            // NOTE: This won't fire if showing infoBox ends up putting it under the current mouse pointer.
            stopInfoboxTimer(e);
        }
        function timerTriggered(e) {
            hideInfobox(e);
        }

解决方案 »

  1.   

    这里可以用mouseover事件,出现信息框,使用mouseout,隐藏信息框,
      

  2.   

    楼主所贴代码的隐藏InfoBox的函数的的参数“e”是不是就是引起事件的对象呢?楼主可以通过调试或者Alert来证实一下,如果是的话,那就好办了,每次调用隐藏函数的时候,直接判断“e”是不是信息框,加上一楼给出的主意,就可以达到楼主所说的效果