簡體   English   中英

如何在IE8中將部分圖像顯示為背景?

[英]How to show part of image as background in IE8?

假設我有一些大圖像,我也有一個98 * 98的div,並希望將圖像的中心部分顯示為縮略圖,即,中心的寬*寬為肖像或高*寬為風景,並縮放為98 * 98。 我有以下PHP和HTML代碼

<?php list($width, $height) = getimagesize($thumbpath);
if ($width > $height) {
  $heightnew = 98;
  $widthnew = 98 * $width / $height;
} else {
  $widthnew = 98;
  $heightnew = 98 * $height / $width;
}
$thumbcss = ' style="background: url(\'' . $thumbpath . '\') no-repeat;' . 
            ' background-size: ' . $widthnew . 'px ' . $heightnew . 'px;' .
            ' -moz-background-size: ' . $widthnew . 'px ' . $heightnew . 'px;' .
            ' background-position: 50% 50%;';
echo '<div class="thumb"' . $thumbcss . '></div>';?>

它在所有高級瀏覽器(IE8除外)上都可以正常工作。 然后,我嘗試將以下內容添加到CSS: filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\\'' . $thumbpath . '\\', sizingMethod=\\'scale\\'); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\\'' . $thumbpath . '\\', sizingMethod=\\'scale\\'); filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\\'' . $thumbpath . '\\', sizingMethod=\\'scale\\'); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\\'' . $thumbpath . '\\', sizingMethod=\\'scale\\'); ,但它的作用是縮放整個圖像而不是縮放的中心。

有沒有辦法處理__ IE8?

給該圖像的div背景:background:url(pathtoimage.ext)不重復中心;

暫無
暫無

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

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