2012-10-09 2 views
0

나는 여러 가지 이미지 태그를 갖고 있으며 아래 HTML과 같이 div로 구성되어 있습니다. Google 크롬에서 이미지 크기를 가져 오는 것이 정의되지 않았습니다.

내 requirment으로는 높이 * 폭 < 5000 1) 2) 제거 correspponding div의 제거이 * 각 이미지의 너비를 높이를 계산하고 다음을 수행 할 것이다 correcsponding 이미지의 '캡 티브'

IE 용과 파이어 폭스 용으로 작동하기 때문에 아래의 스크립트를 사용해 보았습니다. ethod.

$('img[class = "captify"]').each(function(){ 

var $that = $(this), 
picRealWidth = 0, 
picRealHeight = 0, 
imgSize = 0, 
dvHiResCaption = null, 
src = $that.attr('src'), 
rel = $that.attr('rel'); 

// creating a clone in memory 
$('<img/>').attr('src', src) 
.load(function(){ 
picRealWidth = parseInt(this.width); 
picRealHeight = parseInt(this.height); 
}, function(){ 
// called once the load is complete 
imgSize = picRealWidth * picRealHeight; 

if(imgSize < 5000){ 
dvHiResCaption = '#' + rel; 
$(dvHiResCaption).remove(); 
$that.removeClass('captify'); 
} 
}); 
}); 

아무에게도 도움이 될 수 없습니까? 미리 감사드립니다.

답변

0

jsfiddle과 같은 방법이 없습니다. 이 내부로드 함수는 jQuery 객체가 아니지만 JavaScript HTMLElement입니다. 사용 :

..... 
picRealWidth = $(this).width(); // return integer value 
picRealHeight = $(this)..height(); // return integer value 
..... 
+0

당신은있어 그 코드에서 너무 많이 :) –

0

사용 $ (이) .width, $ (이)

$('<img/>').attr('src', src) 
.load(function(){ 
picRealWidth =$(this).width(); 
picRealHeight = $(this).height(); 
....... 
1

대신이 시도 .height의 : '.'

$('img.captify').each(function(i,img){ 
    img.onload = function() { 
     if ((this.width * this.height) < 5000) { 
      $('#' + $(this).attr('rel')).remove(); 
      $(this).removeClass('captify'); 
     } 
    } 
});​