refresh or trigger javascript on window resize -
i using javascript make 2 child div's same height in parent div:
$(function(){ var leftheight = $('.leftblock').height(); var rightheight = $('.rightblock').height(); if (leftheight > rightheight){ $('.rightblock').css('height', leftheight); } else{ $('.leftblock').css('height', rightheight); } });
when resize window 1 of divs getting lot longer again javascript doesn't work anymore. placed exact same script again in window resize function , solves problem!
$(window).resize(function(){ // same script above again });
my question; there cleaner way can use script once refresh or trigger script again on window resize?
sure, declare function , use in both handlers:
function resizedivs() { var leftheight = $('.leftblock').height(); var rightheight = $('.rightblock').height(); if (leftheight > rightheight){ $('.rightblock').css('height', leftheight); } else{ $('.leftblock').css('height', rightheight); } } $(resizedivs); $(window).resize(resizedivs);
Comments
Post a Comment