获取当前图像大小

Get current image size

本文关键字:图像 获取      更新时间:2023-09-26

当我使用 css 缩放图像时,如何获取当前的图像大小?
我正在尝试获取瞬时图像大小,重新调整窗口大小,从而更改图像的大小。

我认为这是某种jQuery .height() .width()

吉斯菲德尔

CSS的

#full_image{
  margin:0;
  padding:0;
  list-style:none;
  white-space: nowrap;
  overflow:hidden;
  position:relative;
  display:inline-block;
}
#full_image ul li img{
  margin:0 auto;
  width:100%;
  max-width:100%
}
#full_image .full_close{
 background-color: red;
 top: 10px;     
 cursor: pointer;    
 height: 29px;
 opacity: 1;
 position: absolute;    
 width: 29px;
 z-index: 999;
 right: 10px;
}
#full_image .next_big{
 background-color: red;
  top: 50%;     
  cursor: pointer;    
  height: 29px;
  opacity: 1;
  position: absolute;    
  width: 29px;
  z-index: 999;
  right: 0px;
}
#full_image .prev_big{
   background-color: red;
   top: 50%;     
   cursor: pointer;    
   height: 29px;
   opacity: 1;
   position: absolute;    
   width: 29px;
   z-index: 999;
   left: 0px;
   color: #222;
    }

该目录

<div id="full_image"> 
  <ul><li><a href="#"> <img src="http://i.telegraph.co.uk/multimedia/archive/01636/saint-tropez-beach_1636818c.jpg" alt="" /></a></li> </ul>    
    <a href="#" class="full_close"></a>
    <a href="#" class="button next_big"></a>
    <a href="#" class="button prev_big"></a>           
 </div>

是的。 这就是我要走的路。 像这样:

$(document).ready(function(){
    $(window).resize(function(){
        console.log($(this).height()); 
        console.log($(this).width()); 
    })
})

下面的更新小提琴

http://jsfiddle.net/mEMNq/2

这应该可以完成工作:

(function($) {
    alert($('img').height());
    alert($('img').width());
})(jQuery);

只是提醒图像的高度和宽度。您可以进行必要的操作。

您可以

尝试使用非标准的IE element.currentStyle属性或DOM Level 2标准getComputedStyle方法。

你去吧 - http://jsfiddle.net/maximua/mEMNq/4/

试试这个:-

(function($) {
    alert($('img').height());
    alert($('img').width());
})(jQuery);

吉斯菲德尔

您也可以尝试使用 element.clientWidth 和 element.clientHeight