JQuery와브라우저 크기에 비례하여 div 크기를 조정하는 방법은 무엇입니까?
$(window).ready(function(){
var w = $(window).width();//to detect the width of the browser
var h = $(window).height();//to detect the height of the browser
$(window).resize(function(){
var w = $(window).width();//new width of the browser
var h = $(window).height();//new height of the browser
$("#left").css('height'+ h 'px.');//this is where I'm not sure how to assign height value according to the browser size.
});
});
내 CSS를
#main
{
width: 100%;
height: 100%;
position: relative;
background: #000000;
}
#left
{
width: 20%;
height: 650px;
position: relative;
float: left;
background: #666666;
}
#right
{
width:80%;
height: 650px;
position: relative;
float:right;
background: #ff9900;
}
내 html로
<div id="main">
<div id="left">
</div>
<div id="right">
</div>
</div>
이제 문제는 왼쪽과 오른쪽 DIV의 높이입니다. 높이를 설정하면 100 %; 그것은 내가 원하지 않는 콘텐츠 높이를 따른다. 높이를 브라우저 높이에 맞게 늘려야합니다. 그래서 높이를 사용하면 650px; 그것은 작동하지만 페이지가 더 크거나 더 큰 크기로 조정되면 어떻게됩니까? 스크롤 막대가 표시되지 않도록 브라우저의 페이지 크기를 확인하고 비례하여 높이를 변경하는 방법은 무엇입니까?
이것은 div의 기본 메커니즘이었습니다. 여기에 아무 것도 쓸 필요가 없습니다. –
여기에서 javascript를 사용하는 것이 더 좋습니다 ....... screen.height 및 screen.width 사용 –