如何检查图片是否已完全加载?
一个小问题。如何检查Jcropbox中的图片是否已完全加载? 我是一个 javascript 初学者,所以如果有人可以提供帮助,我将非常感激。 这是我的代码。
jQuery(document).ready(function () {
jQuery('#<%= imgPerson.ClientID %>').Jcrop({
onChange: showPreview,
onSelect: updateCoords,
aspectRatio: 1,
minSize: [60, 60],
setSelect: [1, 1, 60, 60],
allowSelect: false
});
});
function updateCoords(c) {
jQuery('#<%= X.ClientID %>').val(c.x);
jQuery('#<%= Y.ClientID %>').val(c.y);
jQuery('#<%= W.ClientID %>').val(c.w);
jQuery('#<%= H.ClientID %>').val(c.h);
};
function showPreview(coords) {
var height = '<%= hdnimgHeight.ClientID %>';
var height2 = $(height).value;
var rx = 60 / coords.w;
var ry = 60 / coords.h;
$('#<%= imgPreview.ClientID %>').css({
width: Math.round(rx * 400) + 'px',
height: Math.round(ry * height2) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
};
One little question. How can I check if the picture in the Jcropbox is fully loaded?
I am a javascript beginner so I would be really thankful if someone can help.
Here is my code.
jQuery(document).ready(function () {
jQuery('#<%= imgPerson.ClientID %>').Jcrop({
onChange: showPreview,
onSelect: updateCoords,
aspectRatio: 1,
minSize: [60, 60],
setSelect: [1, 1, 60, 60],
allowSelect: false
});
});
function updateCoords(c) {
jQuery('#<%= X.ClientID %>').val(c.x);
jQuery('#<%= Y.ClientID %>').val(c.y);
jQuery('#<%= W.ClientID %>').val(c.w);
jQuery('#<%= H.ClientID %>').val(c.h);
};
function showPreview(coords) {
var height = '<%= hdnimgHeight.ClientID %>';
var height2 = $(height).value;
var rx = 60 / coords.w;
var ry = 60 / coords.h;
$('#<%= imgPreview.ClientID %>').css({
width: Math.round(rx * 400) + 'px',
height: Math.round(ry * height2) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以监听图像的
onload
事件,当图像在浏览器中完全加载时会触发该事件。尝试这样的事情它还有其他事件,如
onabort
、onerror
等,以防您希望以不同的方式处理它们。You can listen to
onload
event of image which gets triggered when the image is fully loaded in the browser. Try something like thisIt also has other events like
onabort
,onerror
etc in case you wish to handle them differently.