I
I
Ivan Drozhzhin2016-08-17 10:04:46
JavaScript
Ivan Drozhzhin, 2016-08-17 10:04:46

How to make a smooth scroll from a link in Ya.Maps to an anchor?

A page with a Yandex map compiled in the map constructor. Below the map is a description of each point on it. Each point on the map has a link to the anchor below.
The map is called via the view tag

<script type="text/javascript" charset="utf-8" async src="https://api-maps.yandex.ru/services/constructor/1.0/js/?sid=0DjJzvmy4tmRmdqwCASHpQXtV0Bd0E1m&amp;width=100%&amp;height=500&amp;lang=ru_RU&amp;sourceType=constructor&amp;scroll=true"></script>

I am including below script
<script> 
$(document).ready(function(){
  $("#menu").on("click","a", function (event) {
    event.preventDefault();
    var id  = $(this).attr('href'),
      top = $(id).offset().top;
    $('body,html').animate({scrollTop: top}, 1500);
  });
});
</script>

Ideally, I wanted the scroll to the anchor to work when you click on a point on the map, but this is not in my power :) Therefore, I made a link to the anchor in the description of each point.
As a result, the transition remains sharp, the script does not work.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question