从缩放图像中获取宽度 [英] Getting the width from an scaled image
本文介绍了从缩放图像中获取宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Jquery获取图像的宽度,一旦它附加到正文。看看这个小提琴,了解我正在做的事情。
I'm using Jquery to get the width of an image once it is appended to the body. Have a look at this fiddle to get an understanding of what I'm doing.
我想要做的是添加具有约束高度的每个元素,并在缩放后读取相应宽度的一次。你会看到的问题是console.log给了我宽度值0。
What I want to do is add each element with a constrained height and read what the respective width is once after it is scaled. The problem as you will see is that the console.log is giving me the value 0 for the width.
推荐答案
使用jQuery < a href =http://api.jquery.com/load/ =nofollow> .load()
函数进行所有计算图像加载后:
Use jQuery .load()
function to do all the calculation after image load:
var number = 0;
var number = 0;
$(document).ready(function(){
setInterval(function(){
console.log();
$('.container').prepend(
$('<img/>').attr({
src: "http://www.upress.umn.edu/book-division/images-1/other images/blockc.gif/image_thumb"
id:'img' + (number++)
}).load(function(){
console.log($(this).width())
})
},3000);
});
这篇关于从缩放图像中获取宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文