0

I'm trying to capture the window size in certain case and depend of the width I apply a different left position using this code :

 case 'above':
        modal.css({
          'top': buttonPosition.top - modal.outerHeight() + scrollTop,
          'left': $(window).resize(function() { 
                      var i = $(this).width(); 
                      if (i > 735) { buttonPosition.left - 188;}
                      else {
                        buttonPosition.left - 100;
                      }
                    })
        });
        break;

but this don't seem to apply any thing whatever the width of the window the element still in the same position , but when i remove the $(window).resize(function() it works like so :

case 'above':
        modal.css({
          'top': buttonPosition.top - modal.outerHeight() + scrollTop,
          'left': buttonPosition.left - 188;
        });
        break;

but this is don't allow me to change the left position depend on the window size , any help would be greatly appreciated

ZEE
  • 5,100
  • 3
  • 30
  • 47

1 Answers1

1

Try doing this instead:

case 'above':
        modal.css({
          'top': buttonPosition.top - modal.outerHeight() + scrollTop,
          'left': $(window).width() > 735 ? buttonPosition.left - 188 : buttonPosition.left - 100
        });
        break;

For info on the ? syntax see here: Question Mark in JavaScript

Community
  • 1
  • 1
winhowes
  • 6,741
  • 5
  • 27
  • 39