M
M
Mnq2232019-03-24 11:48:30
Mobile development
Mnq223, 2019-03-24 11:48:30

How to disable the script on the mobile version of the site?

Friends, help disable jq script. You need to make sure that it works only on the desktop, and turns off on the mobile.
The script itself:
jQuery('document').ready(function () {
var $top = $(".menu")
$(window).on("scroll", function () {
if ($(window).scrollTop () <= 650) {
$top.fadeIn();
} else {
$top.fadeOut()
}
});
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
ⓒⓢⓢ, 2019-03-24
@Mnq223

for example like this:

jQuery('document').ready(function () {
  var $top = $(".menu");
  var isMobile = $(window).width() < 1280; // <- true, если ширина экрана меньше 1280
  $(window).on("scroll", function () {
    if (isMobile) return; // <- Если ширина экрана меньше 1280, то выходим из функции
    if ($(window).scrollTop() <= 650) {
      ...
    }
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question