javascript - 获取当前图像大小

标签 javascript jquery html css

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

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

JSFIDDLE

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;
    }

HTML

<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()); 
    })

})

下面更新了 fiddle

http://jsfiddle.net/mEMNq/2

关于javascript - 获取当前图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18621593/

相关文章:

Javascript:匹配多个对象数组中的对象+别名

php - 在手机上使用 jQuery 更改背景图片 URL(使用内联 CSS 和 PHP 添加)

javascript - Chrome v51.0.2704.79 上引入的错误 m 无法清空大选择

html - 占位符样式 - 覆盖使用 !important 的样式

php - 验证在网站上输入的用户名密码与MySQL数据库上的密码

javascript - 如何在 C# 通用处理程序中引用从 javascript 接收的反序列化对象属性?

javascript - 样式切换器帮助

javascript - ( react 原生): Execution failed for task ':app:generatePackageList'

javascript - Jquery HTML 选择标签附加重复本身

php - jquery.validate 不适用于选择框