navigation - How do I trigger my jQuery script on resize event -
i have jquery script reorganizes menu select form element, works fine.
i want trigger on .resize() event can´t work. how this?
$(function () { $(window).resize(function () { /* window's width, , check whether narrower 580 pixels */ var windowwidth = $(window).width(); if (windowwidth <= 580) { /* clone our navigation */ var mainnavigation = $('nav.main-navigation').clone(); /* replace unordered list "select" element populated options, , create variable select our new empty option menu */ $('nav.main-navigation').html('<select class="menu"></select>'); var selectmenu = $('select.menu'); /* navigate our nav clone information needed populate options */ $(mainnavigation).children('ul').children('li').each(function () { /* top-level link , text */ var href = $(this).children('a').attr('href'); var text = $(this).children('a').text(); /* append option our "select" */ $(selectmenu).append('<option value="' + href + '">' + text + '</option>'); /* check "children" , navigate more options if exist */ if ($(this).children('ul').length > 0) { $(this).children('ul').children('li').each(function () { /* child-level link , text */ var href2 = $(this).children('a').attr('href'); var text2 = $(this).children('a').text(); /* append option our "select" */ $(selectmenu).append('<option value="' + href2 + '">--- ' + text2 + '</option>'); }); } }); } /* when our select menu changed, change window location match value of selected option. */ $(selectmenu).change(function () { location = this.options[this.selectedindex].value; }); }); });
well, try on resize!
$("#div").resize(function(e){ // when #div element resize });
Comments
Post a Comment