0

Im using scotch panels to make an off canvas menu. I would like to change the width of the panel from 70% to 100% on mobile only. Here is the code i'm using:

jQuery(document).ready(function($){

var panelExample = $('#sidecart').scotchPanel({
    containerSelector: 'body',
    direction: 'left',
    duration: 300,
    transition: 'ease',
    clickSelector: '.toggle-sidecart',
    distanceX: '70%', // this sets the width
    enableEscapeKey: true
});

});

I think I can use the below code but i'm not sure how

if (screen.width >= 768) {
    // make width of panel 100%
}

Can anyone help me out?

Thanks!

ScreamQueen
  • 206
  • 1
  • 4
  • 13

1 Answers1

0

You can do whatever logic you want when you init your panelExample variable.

jQuery(document).ready(function($){

var panelExample = (screen.width >= 768) ?

  $('#sidecart').scotchPanel({
      containerSelector: 'body',
      direction: 'left',
      duration: 300,
      transition: 'ease',
      clickSelector: '.toggle-sidecart',
      distanceX: '100%', // this sets the width
      enableEscapeKey: true
  }) :

  $('#sidecart').scotchPanel({
      containerSelector: 'body',
      direction: 'left',
      duration: 300,
      transition: 'ease',
      clickSelector: '.toggle-sidecart',
      distanceX: '70%', // this sets the width
      enableEscapeKey: true
  });
});

If you're setting lots of different object options, the above example makes sense. In your question, the only thing changing is distanceX, so it might be a bit more readable to make the variable declaration tighter:

jQuery(document).ready(function($){

var panelWidth = (screen.width >= 768) ? "100%" : "70%",
    panelExample = $('#sidecart').scotchPanel({
      containerSelector: 'body',
      direction: 'left',
      duration: 300,
      transition: 'ease',
      clickSelector: '.toggle-sidecart',
      distanceX: panelWidth, // this sets the width
      enableEscapeKey: true
  });

});
Lucas Balzer
  • 316
  • 2
  • 7