Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem is also described on code.google.com, this problem is only in Firefox, but it isn't a Firefox bug:</p> <p><a href="http://code.google.com/p/gmaps-api-issues/issues/detail?id=3652" rel="nofollow">http://code.google.com/p/gmaps-api-issues/issues/detail?id=3652</a> <a href="http://code.google.com/p/gmaps-api-issues/issues/detail?id=1605" rel="nofollow">http://code.google.com/p/gmaps-api-issues/issues/detail?id=1605</a></p> <p>Have also found out a workaround, that is not re-scrolling or re-zooming and works fine:</p> <p>A new ScrollInterceptOverlay derived from google.maps.OverlayView, prepending a div on MapPanes.overlayMouseTarget:</p> <h2>Version with jQuery</h2> <pre><code>// Ensure to have google.maps loaded: // var gmap = new google.maps.Map($googlemap[0], mapOptions); // Define a ScrollInterceptOverlay function var ScrollInterceptOverlay = function (gmap) { if (!(this instanceof ScrollInterceptOverlay)) return; var $div; var $mapDiv; var initialize = function () { $div = $('&lt;div /&gt;').css({ position: 'absolute', top: 0, left: 0, display: 'inline-block' }); var div = $div[0]; if (div &amp;&amp; div.addEventListener) { // Internet Explorer, Opera, Google Chrome and Safari div.addEventListener("mousewheel", mouseScrollStop); // Firefox div.addEventListener("DOMMouseScroll", mouseScrollStop); div.addEventListener("MozMousePixelScroll", mouseScrollStop); } else if (div &amp;&amp; div.attachEvent) { // IE before version 9 div.attachEvent("onmousewheel", mouseScrollStop); } this.setMap(gmap); }; var mouseScrollStop = function (e) { if (e &amp;&amp; e.preventDefault) e.preventDefault(); }; this.onAdd = function () { $div.prependTo(this.getPanes().overlayMouseTarget); }; this.onRemove = function () { var div = $div[0]; if (div &amp;&amp; div.addEventListener) { // Internet Explorer, Opera, Google Chrome and Safari div.addEventListener("mousewheel", mouseScrollStop); // Firefox div.addEventListener("DOMMouseScroll", mouseScrollStop); div.addEventListener("MozMousePixelScroll", mouseScrollStop); } else if (div &amp;&amp; div.attachEvent) { // IE before version 9 div.attachEvent("onmousewheel", mouseScrollStop); } $div.detach(); }; this.draw = function () { if ($mapDiv &amp;&amp; $mapDiv.length === 1) { $div.css({ width: $mapDiv.outerWidth(), height: $mapDiv.outerHeight() }); } }; var base_setMap = this.setMap; this.setMap = function (map) { $mapDiv = $(map.getDiv()); base_setMap.call(this, map); }; initialize.call(this); }; // Setup prototype as OverlayView object ScrollInterceptOverlay.prototype = new google.maps.OverlayView(); // Now create a new ScrollInterceptOverlay OverlayView object: var mapScrollInterceptor = new ScrollInterceptOverlay(gmap); </code></pre> <p>This workaround is using jQuery, required for calculating outerWidth and outerHeight, but also for better reading.</p> <h2>Version with pure javaScript</h2> <p>Tested live: <a href="http://fiddle.jshell.net/fhSMM/7/" rel="nofollow">http://fiddle.jshell.net/fhSMM/7/</a></p> <pre><code>// Ensure to have google.maps loaded: // var gmap = new google.maps.Map(googlemap, mapOptions); // Define a ScrollInterceptOverlay class function var ScrollInterceptOverlay = function () { if (!(this instanceof ScrollInterceptOverlay)) return; var div; // private instance function var mouseScrollStop = function (e) { if (e &amp;&amp; e.preventDefault) e.preventDefault(); }; // public instance function this.onAdd = function () { div = document.createElement('div'); div.style.display = 'inline-block'; div.style.position = 'absolute'; div.style.top = div.style.left = 0; if (div.addEventListener) { // Internet Explorer, Opera, Google Chrome and Safari div.addEventListener("mousewheel", mouseScrollStop); // Firefox div.addEventListener("DOMMouseScroll", mouseScrollStop); div.addEventListener("MozMousePixelScroll", mouseScrollStop); } else if (div.attachEvent) { // IE before version 9 div.attachEvent("onmousewheel", mouseScrollStop); } var pane = this.getPanes().overlayMouseTarget; var firstChild = pane.firstChild; if (!firstChild) { pane.appendChild(div); } else { pane.insertBefore(div, firstChild); } }; // public instance function this.onRemove = function () { if (div) { if (div.removeEventListener) { // Internet Explorer, Opera, Google Chrome and Safari div.removeEventListener("mousewheel", mouseScrollStop); // Firefox div.removeEventListener("DOMMouseScroll", mouseScrollStop); div.removeEventListener("MozMousePixelScroll", mouseScrollStop); } else if (div.detachEvent) { // IE before version 9 div.detachEvent("onmousewheel", mouseScrollStop); } var parent = div.parentNode; parent.removeChild(div); } // do not delete div var'iable div = undefined; }; // public instance function this.draw = function () { var map = this.getMap(); if (map) { var mapDiv = map.getDiv(); if (mapDiv) { var rect = mapDiv.getBoundingClientRect(); div.style.width = rect.width + 'px'; div.style.height = rect.height + 'px'; } } }; }; // Setup prototype as OverlayView object ScrollInterceptOverlay.prototype = new google.maps.OverlayView(); // Now create a new ScrollInterceptOverlay OverlayView object: var mapScrollInterceptor = new ScrollInterceptOverlay(); mapScrollInterceptor.setMap(gmap); </code></pre> <p>Please visit also <a href="http://metadea.de/V/" rel="nofollow">http://metadea.de/V/</a> about what (real) javaScript class functions are, and why I like jQuery :)</p> <p>Works now for me. Also in Firefox, the map is zooming on mousescroll, but no more scrolling the document.</p> <p>Edit: Updated support for MozMousePixelScroll, refined jS</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload