dynamically change CSS on window resize using jQuery -


i'm building restaurant menu system whereby chosen menu slides on over click.

everything's working correctly, however, i'm trying make dynamically resize window.

having massive difficulty this, jquery coming along well, hit wall...

jquery

var $mmenu = $('.menu__main');  if ($mmenu.length > 0) {      var $mnav = $('.menu__nav'),         $mnav_a = $mnav.find('a'),         m = parseint($mnav.outerheight(true), 10),         $contain = $mmenu.closest('.menu-container'),         h = 0,         l = 0;      $mmenu.not(':eq(0)').hide();     $mmenu.eq(0).addclass('active');     $mnav_a.eq(0).addclass('active');      $mmenu.each(function(z) {          var $this = $(this),             $mmenuheight;          $(window).smartresize(function () {             $mmenuheight = parseint($this.outerheight(true), 10) + m;         });          $this.css('height','auto');          $this.css({             zindex: z+1,             position: 'absolute',             top: m + "px",             left: l,             height: $mmenuheight + "px"         });          l = l - $this.outerwidth();      });      $(window).smartresize(function () {         $contain.height($mmenu.eq(0).height());     });  }  $(window).trigger("smartresize"); 

the 2 $(window).smartresize() functions incorrectly used know, guidance on appreciated. first setting height individual menus, second menu container.

enter image description here

you should using media queries sort of work. it's easier , supported. unsure why need position absolutely menu items. can accomplish sliding out functionality using hover in combination relative positioning or transforms. way dont need worry setting individual heights.

as side note, web application's function resized on fly or on initial load?

docs

https://developer.mozilla.org/en-us/docs/web/guide/css/media_queries?redirectlocale=en-us&redirectslug=css%2fmedia_queries

your code might like

@media screen , (max-width:/* desired breakpoint*/) {      .menu li {           width:100%;           max-width:/* maximum size want menu item */      } } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -