I want to animate (fadein, fadeout) a marker in my GoogleMaps application (Web).
How can i assign any css class to a marker?
Or how can i access the specific marker? Do they have selectors like :after or something?
If not, whats the easiest way of applying animations to them?
The DOMNode that contains the image used for the marker isn't available via the API.
Furthermore, by default the markers will not be single DOMNodes, they will be drawn via canvas.
But the Marker-Image may be accessible via CSS when you use a unique icon-URL for each Marker.
Sample(using jQuery):
How ist works:
The sample uses a single image as Marker-Icon (http://www.google.com/mapfiles/marker.png)
via CSS we apply a opacity. You may notice that there is a i-parameter inside the URL. This parameter will be used to make the img-src unique.
I use a variable which will be incremented to get a unique img-src:
Now you'll be able to select the
<img/>
-element used for the marker, e.g. onmouseover/onmouseout via a attribute-selector.When you wan't to use vanilla javascript you may use
document.querySelector
to access the image.Note: you must set the
optimized
-option of the marker tofalse
(this will force the API to render the marker as a single element)Demo: http://jsfiddle.net/doktormolle/nBsh4/
There is a trick that can work if you for example want to change the cursor for the marker Add this:
and
works like a charm
An easy way is, select the marker and add a class the that selection.But for that you have to give each marker a title. Any animation would not work except google ones.
$("div[title=\"" + name+ "\"]").addClass("aClass")
I hope this helps someone.