E
E
Evgeny Fatzilla2015-04-22 12:49:42
JavaScript
Evgeny Fatzilla, 2015-04-22 12:49:42

How to change the position of existing markers on the Yandex map when hovering with the mouse?

There is a map on the site (drupal 7).
It is necessary to make it so that when you hover over the map marks with the mouse, they move slightly up (and then, accordingly, return back), i.e. Roughly speaking, handle the "hover" event.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gracer, 2015-04-22
@FatSurfer

Well, to put it bluntly

ymaps.ready(init);

function init() {
    var myMap = new ymaps.Map('map', {
            center: [55.755773, 37.617761],
            zoom: 9
        }),
        myPlacemark = new ymaps.Placemark(myMap.getCenter());

    myMap.geoObjects.add(myPlacemark);

    myPlacemark.events
        .add('mouseenter', function (e) {
            // Ссылку на объект, вызвавший событие,
            // можно получить из поля 'target'.
            var coords = e.get('target').geometry.getCoordinates();
            coords[0] += 0.001;
            coords[1] += 0.001;
            e.get('target').geometry.setCoordinates(coords);
        })
        .add('mouseleave', function (e) {
            var coords = e.get('target').geometry.getCoordinates();
            coords[0] -= 0.001;
            coords[1] -= 0.001;
            e.get('target').geometry.setCoordinates(coords);
        });
}

T
teotlu, 2015-04-22
@teotlu

We made custom labels on our map using the template factory built into the API . And then you can just write transition or animation on :hover in CSS, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question