簡體   English   中英

檢測應用了最大寬度的圖像

[英]Detect image who a max-width applied

我想為所有與max-width css屬性有關的圖像添加一個類。

例如在一個div中,我有兩個圖像:數字1:寬度200和高度200數字2:寬度50和高度50

我的div上有一個屬性max-width:max-width:50px

我可以通過jquery還是通過css屬性檢測到我的圖像是否已調整大小?

根據我對您的問題的了解,這里是如何解決問題的方法。

var $imageContainer = $("div");
var maxWidth = $imageContainer.css('max-width');
$imageContainer.find('img').filter(function(){
      return $(this).height() > maxWidth;
})
.addClass('maxWidth');//Define this class with appropriate styles

jQuery沒有任何內部“ css值”選擇器。 您可以構建一個,但是您可能只想做類似的事情

$("img").each(function() {
   if ($(this).css('max-width') == '50px') {
      $(this).addClass('detected');
   }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM