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
Post a Comment