javascript - Change css dynamically with window.resize() -


is there variant change block width window.resize(), if have set rules?

let's have block width , width jquery:

var $block_1_width = $(".block_1").width(); 

i need make block have same width, first one. so, write:

var $block_2 = $(".block_2");  $block_2.css("width", $block_1_width + "px"); 

if load page, work fine, want them dynamically keep same size @ window width when user resizes page. so, try:

$(window).resize(function() {   $block_2.css("width", $block_1_width + "px"); }); 

and doesn't. know when wrote $block_2.css("width", $block_1_width + "px"), jquery set inline style $block_2. mean cannot override window.resize()?

you need re-calculate $block_1_width after resize so:

$(window).resize(function() {     var $block_1_width = $(".block_1").width();     $block_2.css("width", $block_1_width + "px"); }); 

Comments

Popular posts from this blog

How to show in django cms breadcrumbs full path? -

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -