admin管理员组文章数量:1382169
Using Dropzone.js, I need to detect the dimesions of the image when added files and apply them to its parent .details
div. The following code code works and return an alert with the added image width.
myDropzone.on("addedfile", function(file, xhr) {
var fr;
fr = new FileReader;
fr.onload = function() {
var img;
img = new Image;
img.onload = function() {
return alert(img.width);
};
return img.src = fr.result;
};
return fr.readAsDataURL(file);
});
The thing is that I have no idea how to assign the width to its parent .details
element which set the preview width of the preview.
I try replacing the alert for this code but it doesn't do anything.
$(this).parent('.details').css('height',img.height);
I'm a bit lost in how to relate the value inside the onload function to applying it to its parent class.
Using Dropzone.js, I need to detect the dimesions of the image when added files and apply them to its parent .details
div. The following code code works and return an alert with the added image width.
myDropzone.on("addedfile", function(file, xhr) {
var fr;
fr = new FileReader;
fr.onload = function() {
var img;
img = new Image;
img.onload = function() {
return alert(img.width);
};
return img.src = fr.result;
};
return fr.readAsDataURL(file);
});
The thing is that I have no idea how to assign the width to its parent .details
element which set the preview width of the preview.
I try replacing the alert for this code but it doesn't do anything.
$(this).parent('.details').css('height',img.height);
I'm a bit lost in how to relate the value inside the onload function to applying it to its parent class.
Share Improve this question asked Apr 15, 2013 at 8:52 MartinMartin 11.3k23 gold badges86 silver badges143 bronze badges1 Answer
Reset to default 5With the latest version of dropzone you don't have to write this code yourself.
Simply read the file.width
and file.height
properties that are set on the file
object when the thumbnail is generated.
The problem, why your CSS doesn't affect the element, is because you didn't specify the unit, px
in this case. So your code can be:
myDropzone.on("thumbnail", function(file) {
$(this.element).parent('.details').css('height', file.height + 'px');
});
本文标签: javascriptHow to detect dimensions of file using File API and DropzonejsStack Overflow
版权声明:本文标题:javascript - How to detect dimensions of file using File API and Dropzone.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744465829a2607507.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论