Javascript 获取当前图像大小
使用css缩放图像时,如何获取当前图像大小?Javascript 获取当前图像大小,javascript,jquery,html,css,Javascript,Jquery,Html,Css,使用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 u
我试图得到即时的图像大小,窗口被重新调整大小,从而改变图像的大小 我想这是某种
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;
}
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());
})
})
更新小提琴如下
试试这个:-
(function($) {
alert($('img').height());
alert($('img').width());
})(jQuery);
您还可以尝试使用和,这样可以完成工作:
(function($) {
alert($('img').height());
alert($('img').width());
})(jQuery);
只是提醒图像的高度和宽度。您可以执行必要的操作。您可以尝试使用非标准IE
元素.currentStyle
属性或DOM Level 2 standardgetComputedStyle
方法
给你-
console.log($(this.height())
应该是console.log($(this.height())代码>与下一行相同..只是简单的事情,没什么大不了的。你还有一个额外的
k。thnx。另一个div是“想知道谁问了这个问题”。我刚刚添加了JS;)谢谢,这已经起作用了。我怎么能说存储高度并将其用作全局变量呢?谢谢,但这只起作用一次。每次你调整窗户尺寸时,我都需要它持续工作