Jquery conditional fade by window width -


i make submenu fadein, above 850px window width. code works if refresh page, i'd make when resize window ( or change phone orienation ) well. what's wrong?

function winsize() {     var winwidth = $(window).width();     if (winwidth > 850) {         $('#main-menu > ul > li').on({             mouseenter: function() {                 $(this).find("ul").fadein(300);             },             mouseleave: function() {                 $(this).find("ul").fadeout(300);             }         });     } }  $(window).on("load resize", winsize); 

try moving condition inside of .on. binding event when on load windows size > 850 , not effecting actual .on events

function winsize() {     $('#main-menu > ul > li').on({         mouseenter: function() {             var winwidth = $(window).width();              if (winwidth > 850) {                 $(this).find("ul").fadein(300);             }         },         mouseleave: function() {             var winwidth = $(window).width();              if (winwidth > 850) {                 $(this).find("ul").fadeout(300);             }         }     }); }  $(window).on("load resize", winsize); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -