리사이즈에 대해 질문합니다. > 그누4 질문답변

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.

리사이즈에 대해 질문합니다. 정보

리사이즈에 대해 질문합니다.

본문

가로 세로를 설정하여 설정된 값 이상으로 이미지를 늘어나지 않게 하려면 어떻게 수정해야 할까요?
아래 링크와 같은 형식처럼요. ^^
 
 
아래 스크립트는 가로 200 이상으로 늘어나지 않습니다.
세로도 설정하려니 방법을 모르겠습니다. ^^
답변 부탁드립니다.
<img src='URL' name='target_resize_image[]'>
 
<script language="JavaScript">
// HTML 로 넘어온 <img ... > 태그의 폭이 테이블폭보다 크다면 테이블폭을 적용한다.
function resize_image()
{
    var target = document.getElementsByName('target_resize_image[]');
    var image_width = parseInt('200');
    var image_height = 0;
    for(i=0; i<target.length; i++) {
        // 원래 사이즈를 저장해 놓는다
        target[i].tmp_width  = target[i].width;
        target[i].tmp_height = target[i].height;
        // 이미지 폭이 테이블 폭보다 크다면 테이블폭에 맞춘다
        if(target[i].width > image_width) {
            image_height = parseFloat(target[i].width / target[i].height)
            target[i].width = image_width;
            target[i].height = parseInt(image_width / image_height);
        }
    }
}
window.onload = resize_image;
</script>
  • 복사

댓글 전체

if(target[i].width > image_width) {
            image_height = parseFloat(target[i].width / target[i].height)
            target[i].width = image_width;
            target[i].height = parseInt(image_width / image_height);
        }
}

============== 위 부분을 아래 부분처럼 해 보세요. ==========================

if( target[i].width > target[i].height)
    if(target[i].width > image_width) {
          target[i].width = image_width;
          //target[i].height = "";
} else {
    if(target[i].height > image_height ) {
          target[i].height = image_height ;
          //target[i].width = "";
}
===============================================================
//를 없애보기도 하세요
© SIRSOFT
현재 페이지 제일 처음으로