R
R
Roman2015-06-26 03:11:02
JavaScript
Roman, 2015-06-26 03:11:02

Is it possible to change the height of the sidebar in this way depending on the width of the screen?

On wide screens I want the height of the sidebar to be equal to the height of the post, but when viewed from phones, the sidebar runs under the post and I need the height of the sidebar to be determined as usual based on the content of the sidebar.

Is it correct to use such a function?

$(document).ready(function(){
     var $winWidth = $(window).width(); 
     if($winWidth > 757) { 
            $("#sidebar").css("height", $(".post").height());
     }
;})

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad, 2015-06-26
@llgruff

function fixSize(){

     if($(window).width() > 757) { 
       $('#sidebar').css({
          'height':  $(".post").height()
        });
     } else [
       $('#sidebar').css({
          'height':  'auto'
        });
     }

}
    $(window).resize(fixSize);
    fixSize();

I would do that, but I don't know if it's right.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question