How can I make a simple script that will expand/shrink div based on screen size on load and screen resize? I'm new to java script here is my current code. Its a menu that on tablets and phones that is collapsed by default and click-able to expand its contents. But on desktops and laptops it is already expanded by default.
if ( $(window).width() > 600) {
$(function(){
$('.header').click(function(){
$(this).closest('.container').toggleClass('collapsed');
});
});
//container is expanded on large screen resize or load
}
else {
//container is collapsed on load or screen resize or load
}
.container{
width:300px;
background:#ccc;
margin:10px;
float:left;
}
.header{
background:url('http://cdn1.iconfinder.com/data/icons/vaga/arrow_up.png') no-repeat;
background-position:right 0px;
cursor:pointer;
}
.collapsed .header{
background-image:url('http://cdn2.iconfinder.com/data/icons/vaga/arrow_down.png');
}
.content{
height:auto;
min-height:100px;
overflow:hidden;
transition:all 0.3s linear;
-webkit-transition:all 0.3s linear;
-moz-transition:all 0.3s linear;
-ms-transition:all 0.3s linear;
-o-transition:all 0.3s linear;
}
.collapsed .content{
min-height:0px;
height:0px;
}
<div class="container">
<div class="header">Bla blah</div>
<div class="content">
<p> Some content here </p>
</div>
</div>