D
D
Denis Artemiev2016-12-12 09:33:26
css
Denis Artemiev, 2016-12-12 09:33:26

How to fix draqger in Yandex Maps that slides down when clicked?

Hello, the problem is as follows: The lesson https://tech.yandex.ru/maps/jsbox/2.1/dragger was
taken from the Yandex sandbox . in development), when you click on the dragger, it immediately goes down 5,000 pixels: Red marks where it was . Any thoughts on what it might be? I would be glad for any help PS: On the site, a little higher there is another card, but under a different ID
2c20f2fc8f874651aaa419377e828271.png
d79a16c95b1a459ea85e25930eb2dfe1.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Artemyev, 2016-12-13
@ArtDenis

I found the answer, I needed to think more)
I suspected that it was all about position.
If the element has position:absolute, then the coordinates are considered from any parent with a position other than static. If there is no such parent, then from the beginning of the site.
Thus, having made position: static for all parents, dragger began to work correctly. But this did not suit me, as the template collapsed.
Then I found the function that was causing this error and replaced ONE word - offset() with position() - in the second line of this code:

function onDraggerStart(event) {
        var offset = markerElement.position(),
            position = event.get('position');
        // Сохраняем смещение маркера относительно точки начала драга.
        markerOffset = [
            position[0] - offset.left,
            position[1] - offset.top
        ];
        markerPosition = [
            position[0] - markerOffset[0],
            position[1] - markerOffset[1]
        ];

        applyMarkerPosition();
    }

The differences between these functions (offset() and position()) differ in that offset is the coordinates from the beginning of the site, and position() is from the parent element.
Because our dragger was position: absolute and its parent was position: relative. We needed coordinates from the parent, which solved my problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question