javascript - If Statment depending on screen width -
i have created js if-statment, should detect screen width , change css properties depending on screen width. if screen wider 700px, #header_menu should extended. if resolution below 700, #menu should extended (by clicking trigger).
all in function working, first time resize window. not sure mistake ...
thanks ;)
$(document).ready(function(){ $(window).on('load resize', function checkposition(){ if (window.matchmedia('(max-width: 700px)').matches) { $("#menu_trigger").click(function(){ $("#menu").css('width', '90%'); $("#closer, #header").css('margin-left', '90%'); $("#closer, #header").css('margin-right', '-90%'); }); } else { $("#menu_trigger").click(function(){ $("#header_menu").css('width', 'auto'); }); } });
});
engages resize event of window function , try this
$(document).load($(window).bind("resize", checkposition)); function checkposition(){ if (window.matchmedia('(max-width: 700px)').matches) { $("#menu_trigger").click(function(){ $("#menu").css('width', '90%'); $("#closer, #header").css('margin-left', '90%'); $("#closer, #header").css('margin-right', '-90%'); }); } else { $("#menu_trigger").click(function(){ $("#header_menu").css('width', 'auto'); }); } }
every time page resized, function called
Comments
Post a Comment