I had the following problem today, I created a function that checks the size of the browser window and if it is greater than 1300
, li receives two classes and the link ( <a>
) inside it receives an event of mouseover
and mouseout
.
Otherwise, it only adds three classes to li
. I call this function in the page load and resize function of window
so that when it is resized it also checks the size of the window.
Everything is beautiful and such, but the problem happens, when I resize it, it continues with the events of li
, even the window receiving a new width
. But when I refresh with the page smaller than the value of 1300
, it does not get the event of mouseover
and mouseout
.
Does anyone have any idea why this happens?
Follow the code below:
var areaRestrita = function(larguraJanela) {
if(larguraJanela > 1300) {
$('#menu-item-7436').addClass('barra-lateral-area-restrita-default area-restrita-default')
.removeClass('area-restrita');
$('#menu-item-7436>a').mouseover(function(v){
$('#menu-item-7436')
.removeClass('barra-lateral-area-restrita-default area-restrita-default')
.addClass('barra-lateral-area-restrita area-restrita');
});
$('#menu-item-7436>a').mouseout(function(v){
$('#menu-item-7436')
.removeClass('barra-lateral-area-restrita area-restrita')
.addClass('barra-lateral-area-restrita-default area-restrita-default');
});
} else {
$('#menu-item-7436').addClass('area-restrita')
.removeClass('barra-lateral-area-restrita barra-lateral-area-restrita-default area-restrita-default')
}
}
areaRestrita($(window).width());
$(window).resize(function(){
areaRestrita($(window).width());
});