如何使带有谷歌地图的网站使用鼠标滚轮事件进行平移而不是缩放?

发布于 2024-10-08 17:47:50 字数 518 浏览 8 评论 0原文

我正在使用谷歌地图(v3)进行混搭,以根据实时 GPS 数据显示波士顿公交车的位置。 Google 通常使用滚动进行缩放,但我认为平移更有意义,特别是随着越来越多的计算机(尤其是 Mac)具有两指滚动,允许水平和垂直滚动。如果我可以获取滚动事件,我可以触发平移,但我不知道如何获取它们。我找到了 mousewheel jquery 插件,但它似乎只能轻松检测垂直滚动。 根据mozilla,firefox post 3.5为事件提供了“axis”属性,但是我找不到其他浏览器的任何内容。这是否太新而无法得到很好的支持?

I'm making a mashup with google maps (v3) to show where boston's buses are from realtime 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末が日狂欢 2024-10-15 17:47:50

查看我在 GitHub 上的“平滑滚动”项目。它的目的正是使这成为可能:

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

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

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

若能看破又如何 2024-10-15 17:47:50

我之前使用过这段代码来检测鼠标滚轮事件 - 也许有一些用处。在 IE6+ 和 FF1.0+ 中工作正常 - 但未经最新浏览器的测试!

/** 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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文