'리사이징'에 해당되는 글 1건

  1. 2008.02.15 이미지 자동 리사이즈 관련 함수

사용법

<img src="이미지주소" onload="image_auto_resize(this,180,180);" nmouseover="image_auto_resize(this,180,180);">
지정된 이미지에 자동 리사이즈를 적용합니다.

사용법2

 image_auto_resize_inarea(document.getElementById('div_area'),100,'',true);
document.getElementById('div_area') 안에서의 모든 img에 자동 리사이즈를 적용합니다.

//============================================================================
// 이미지 자동 리사이즈
//============================================================================
function image_auto_resize(this_s,width,height){
 var ta_image = new Image();
 ta_image.src = this_s.src;
  if(!width){this_s.removeAttribute('width');
  this_s.style.width='auto';}
  else if(width < ta_image.width){
   this_s.width = width;
  }else{
   this_s.width = ta_image.width;
  }
  if(!height){this_s.removeAttribute('height');
  this_s.style.height='auto';}
  else if(height < ta_image.height){
   this_s.height = height;
  }else{
   this_s.height = ta_image.height;
  }
}

function image_auto_resize_inarea(this_s,width,height,view){
//this_s안의 모든 이미지는 자동 리사이즈 된다.
 //alert!!(this_s.childNodes.length);
 if(!view){view=true;}
 if(!this_s){return;}
 if(this_s.nodeType!=1){return;}
 for(var i=0,m=this_s.childNodes.length;i<m;i++){
  var ta = this_s.childNodes[i];
 
  if(ta.nodeName=='IMG'){
   //ta.style.border='1px solid #333333';  
   image_auto_resize(ta,width,height);

   if(view){
    if(!ta.title){ta.title=ta.src;}
    if(!ta.onclick){
     ta.style.cursor='pointer';
     ta.onclick=function(){js_image_view(this,1);}
    }
    if(!ta.onload)
     ta.onload=function(){image_auto_resize(this,width,height);}
    if(!ta.onmouseover)  
     ta.onmouseover=function(){image_auto_resize(this,width,height);}
   }
  }
  if(ta.childNodes.length>0){
   image_auto_resize_inarea(ta,width,height);
  }
 }
 return;

}

Posted by 알 수 없는 사용자
,