开发者

How can I make my site with a google map use mousewheel events for panning instead of zooming?

I'm making a mashup with google maps (v3) to show where boston's buses are from realti开发者_JAVA技巧me gps data. Google usually uses scrolling for zooming, but I think panning would make more sense, especially as more computers (especially macs) have two-finger scrolling, which allows both horizontal and vertical scrolling. If I could get at the scroll events, I could trigger panning, but I can't see how to get them. I found the mousewheel jquery plugin, but it only seems to detect vertical scrolling easily. According to mozilla, firefox post 3.5 gives the event an "axis" property, but I can't find anything for other browsers. Is this just too new to be well supported?


Check out my 'Smooth Scrolling' project on GitHub. It aims to make exactly this possible:

http://bentomas.github.com/smooth-scrolling/


Ive used this code before to detect mouse wheel events - maybe of some use. Works fine in IE6+ and FF1.0 + - untested with very latest browsers though !

/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
function handle(delta) {
        if (delta < 0)
        …;
        else
        …;
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
    event.returnValue = false;
}

/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜