R
R
Roman Egliens2019-05-29 23:27:11
JavaScript
Roman Egliens, 2019-05-29 23:27:11

Can anyone help with Yandex map and JS?

Guys, please help with the Yandex map, namely with "Media queries" but only in JavaScript.
I tried to use breakpoint but it didn't help
https://jsfiddle.net/wpk9z5t8/
here is the page itself:
business.egliens.ru/about.html
I need the map center to change its coordinates to 576
how to implement it better, can you tell me?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2019-05-30
@egrom92

one.

$(window).resize(function () {
  if ($(window).width() < 576) {
    myMap.setCenter([57.767265, 40.925358]);
  }
});

function myFunction(x) {
  if (x.matches) { // If media query matches
    myMap.setCenter([57.767265, 40.925358]);
  } 
}

var x = window.matchMedia("(max-width: 576px)")
myFunction(x) // Call listener function at run time
x.addListener(myFunction) // Attach listener function on state changes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question