如何检查图片是否已完全加载?

发布于 2024-12-19 17:27:16 字数 1048 浏览 5 评论 0原文

一个小问题。如何检查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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺渁∝ 2024-12-26 17:27:16

您可以监听图像的 onload 事件,当图像在浏览器中完全加载时会触发该事件。尝试这样的事情

<img src=".." onload="javascript:alert('Image loaded');" />
//Here you can call any javascript method in the onload event

它还有其他事件,如 onabortonerror 等,以防您希望以不同的方式处理它们。

You can listen to onload event of image which gets triggered when the image is fully loaded in the browser. Try something like this

<img src=".." onload="javascript:alert('Image loaded');" />
//Here you can call any javascript method in the onload event

It also has other events like onabort, onerror etc in case you wish to handle them differently.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文