我似乎无法将img的宽度和高度放入另一个类css中。如果你能给我一个很好的提示! 这是我的代码:
$('.Main_hover').each(function() {
var $this = $(this);
var w = $this.find('img').width();
var h = $this.find('img').height();
$(".fusion-button-wrapper").css('height', h);
$(".fusion-button-wrapper").css('width', w);
});
当然它包裹着一个文件。
这是我想要获取图像宽度和高度的HTML:
<div class="imageframe-align-center">
<span class="fusion-imageframe imageframe-none imageframe-1 hover-type-none Main_hover">
<a class="fusion-no-lightbox" href="http://lowette.devel.growcreativity.be/portfolio-items/dummy3/" target="_self">
<img src="http://lowette.devel.growcreativity.be/wp-content/uploads/2016/01/lowette_blok1_1.png" alt="Blok1_1" class="img-responsive"> </a>
</span>
</div>
这里是div类,我想给出宽度和高度:
<div class="fusion-button-wrapper"></div>
答案 0 :(得分:3)
最好在加载img
后执行您正在执行的操作,因为webkit浏览器在加载图像后设置height和width属性。文件准备就绪后可能会或可能不会。
$('.Main_hover img').load(function() {
$(".fusion-button-wrapper").width(this.width);
$(".fusion-button-wrapper").height(this.height);
});
&#13;
.fusion-button-wrapper{
background: blue;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="imageframe-align-center">
<span class="fusion-imageframe imageframe-none imageframe-1 hover-type-none Main_hover">
<a class="fusion-no-lightbox" href="http://lowette.devel.growcreativity.be/portfolio-items/dummy3/" target="_self">
<img src="http://lowette.devel.growcreativity.be/wp-content/uploads/2016/01/lowette_blok1_1.png" alt="Blok1_1" class="img-responsive"> </a>
</span>
</div>
<div class="fusion-button-wrapper"></div>
&#13;
答案 1 :(得分:0)
您可以使用jQuery的width
clientHeight
功能和clientWidth
$('.Main_hover').each(function() {
var $this = $(this);
var h = $this.find('img')[0].clientHeight;
var w = $this.find('img')[0].clientWidth;
$(".fusion-button-wrapper").height(h);
$(".fusion-button-wrapper").width(w);
});
的javascript
plupload.html5.js