Medvjed Jedan Medvjed Jedan - 4 months ago 21
Javascript Question

Sidr.js menu disable on desktop

I am using www.berriart.com/sidr/ jQuery script that creates side menu from my HTML menu.
It works perfectly, but i would like to show the "standard" menu on resolutions bigger than 480px and the sidemenu on resolutions bellow 480px.

I am triggering it with :

<script>
$(document).ready(function() {
$('#simple-menu').sidr();
});
</script>


and i was wondering how can i limit this script to only run when the screen is bellow 480px?

Sorry, JS newbie here :)

Answer

You could use

$(window).width() $(window).height()

to get the width and height of the screen and use it accordingly.

<script>
$(document).ready(function() {
  var width = $(window).width();
   if (width<=480) {
     $('#simple-menu').sidr();
   }
  else
  {
     // you could call the other version of the slider.
   }
});
</script>
Comments