2009-12-09 54 views
0
$(document).ready(function() { 
var pic = $(".pic"); 

// need to remove these in of case img-element has set width and height 
$(".pic").each(function() { 
    var $this = $(this); 
    $this.css({width: 'auto', height: 'auto'}); 

    var pic_real_width = $this.width(); 
    var pic_real_height = $this.height(); 
    if(pic_real_width<100){ 
    $(".pic").css("display","none"); 
    } 
    }); 

}); 

我需要此检查.pic类的所有图像(它已经这样做)的高度,然后添加一个display:none给那些有一定大小的人。 (例如,如果一个img已根据100像素宽度它不应该被显示)JQuery高度条件

+1

没有你5分钟前问同样的问题? http://stackoverflow.com/questions/1873419/jquery-get-height-width – marcgg 2009-12-09 12:16:49

+0

它非常相似,这是指的代码。 – Carvefx 2009-12-09 12:22:41

回答

0

这应该做的伎俩:

$(document).ready(function() { 
    // need to remove these in of case img-element has set width and height 
    $(".pic").each(function() { 
     var $this = $(this); 
     $this.css({width: 'auto', height: 'auto'}); 

     var pic_real_width = $this.width(); 
     var pic_real_height = $this.height(); 
     if(pic_real_width<100){ 
      $this.css("display","none"); 
     } 
    }); 
}); 

您洁具再次引用集合而不是一个具体的元素

+0

谢谢,它的工作! – Carvefx 2009-12-09 12:27:44