I've built a Google map where the markers bounce on rollover of some external links. I've created this short function to bounce the marker:
function makeBounce(marker) {
marker.setAnimation(google.maps.Animation.BOUNCE);
setTimeout(function(){ marker.setAnimation(null); }, 750);
}
and I'm using this to execute it:
<a onmouseover="javascript:map.panToBounds(bounds);makeBounce(markersArray[1]);" href="javascript:google.maps.event.trigger(markersArray[1], 'click');">Marker name</a>
What I'm noticing is that just before the markers bounce they flash. It's almost imperceptible, but it's enough to be really annoying (especially since Google's own blog post launching bouncing markers is very smooth: .html).
I've created a JS Fiddle here which demonstrates it: / (roll over the blue links to see the problem).
I've tried it in Firefox9 and Chrome 16 and the problem is there in both.
Any thoughts?
The problem seems to be that the marker image is dynamically (re)loaded just before the bounce, because in Chrome I see the 'no image' box just before the marker reappears then bounces.
EDIT: I've altered the code to make use of a maps API listener instead of a Javascript function, in the hope that the API code might be a bit more efficient, but no joy :(
google.maps.event.addListener(marker, 'dblclick', (function(marker, i) {
return function() {
marker.setAnimation(google.maps.Animation.BOUNCE);
setTimeout(function(){ marker.setAnimation(null); }, 750);
}
})(marker, i));
I'm using dblclick
because I don't want mouseover
, which would mean the animation was triggered when the markers are rolled over. I only want the animation triggered when the external links are rolled over:
<a onmouseover="javascript:google.maps.event.trigger(markersArray[1], 'dblclick');">Link name</a>
I've updated the JS Fiddle to reflect this: /
I've built a Google map where the markers bounce on rollover of some external links. I've created this short function to bounce the marker:
function makeBounce(marker) {
marker.setAnimation(google.maps.Animation.BOUNCE);
setTimeout(function(){ marker.setAnimation(null); }, 750);
}
and I'm using this to execute it:
<a onmouseover="javascript:map.panToBounds(bounds);makeBounce(markersArray[1]);" href="javascript:google.maps.event.trigger(markersArray[1], 'click');">Marker name</a>
What I'm noticing is that just before the markers bounce they flash. It's almost imperceptible, but it's enough to be really annoying (especially since Google's own blog post launching bouncing markers is very smooth: http://googlegeodevelopers.blogspot./2010/12/map-markers-they-move.html).
I've created a JS Fiddle here which demonstrates it: http://jsfiddle/RmDuz/ (roll over the blue links to see the problem).
I've tried it in Firefox9 and Chrome 16 and the problem is there in both.
Any thoughts?
The problem seems to be that the marker image is dynamically (re)loaded just before the bounce, because in Chrome I see the 'no image' box just before the marker reappears then bounces.
EDIT: I've altered the code to make use of a maps API listener instead of a Javascript function, in the hope that the API code might be a bit more efficient, but no joy :(
google.maps.event.addListener(marker, 'dblclick', (function(marker, i) {
return function() {
marker.setAnimation(google.maps.Animation.BOUNCE);
setTimeout(function(){ marker.setAnimation(null); }, 750);
}
})(marker, i));
I'm using dblclick
because I don't want mouseover
, which would mean the animation was triggered when the markers are rolled over. I only want the animation triggered when the external links are rolled over:
<a onmouseover="javascript:google.maps.event.trigger(markersArray[1], 'dblclick');">Link name</a>
I've updated the JS Fiddle to reflect this: http://jsfiddle/RmDuz/1/
Share Improve this question edited Jun 20, 2020 at 22:13 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jan 7, 2012 at 15:11 melat0ninmelat0nin 8791 gold badge16 silver badges38 bronze badges1 Answer
Reset to default 7I ran into this problem as well. It turns out setting MarkerOptions optimized: false
or draggable: true
will stop the markers from flashing before they animate.
A non-optimized marker:
// Create a non-optimized marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(39.107182, -123.501868),
map: map,
optimized: false // stops the marker from flashing
});
// Bounce once
marker.setAnimation(google.maps.Animation.BOUNCE);
marker.setAnimation(null);
A draggable marker:
// Create a draggable marker
var draggableMarker = new google.maps.Marker({
position: new google.maps.LatLng(39.107182, -123.501868),
map: map,
draggable: true // stops the marker from flashing
});
// Bounce once
draggableMarker.setAnimation(google.maps.Animation.BOUNCE);
draggableMarker.setAnimation(null);
If you take a look at the Google example, you'll see that they set draggable: true
.