如何在 jQueryMobile 中为图像绑定 Load 事件

发布于 2024-10-10 20:48:27 字数 1184 浏览 0 评论 0原文

我有一个运行 jQuery Mobile 1.0a2 的移动网站,目前正在通过 iPhone 模拟器在 Mobile Safari 中测试固件 4.1。

我似乎无法绑定到图像的加载事件。

我有一个简单的缩略图库和一张大图像。当您单击缩略图时,它会更改主 imgsrc 属性,

该 js 使用 live('click' 方法进行绑定 我的问题是我需要有关此点击

$('.gallery-navigation img').live('click',function() {
  // change source of main image to new
  $.mobile.pageLoading(); // show jquerymobile loading message
});

的反馈,因此我想显示一条加载消息(由 jquerymobile 提供),然后在图像加载后将其隐藏

。实际的 其中 src 正在更改,我尝试了以下操作:

$("#gallery_image_large").bind("load", function () {
   $.mobile.pageLoading(true); // hide jquerymobile loading message
});

中无效。

这在我的桌面上的 Safari 中有效,但在上面提到的 iPhone模拟器 >供参考:

更新: 我正在尝试 JQuery 图像在 MobiOne iPhone 模拟器上加载失败,这解释了如何通过“检查.complete”来手动实现.load

I have a mobile website running jQuery Mobile 1.0a2 and I'm currently testing in Mobile Safari for Firmware 4.1 via the iPhone Simulator.

I cannot seem to bind to the load event for an image.

I have a simple gallery of thumbnails and a large image. When you click on a thumbnail it changes the src attribute of the main img

The js for that uses the live('click' method to bind and it works just fine.

$('.gallery-navigation img').live('click',function() {
  // change source of main image to new
  $.mobile.pageLoading(); // show jquerymobile loading message
});

My problem is that I need feedback on this click, so I wanted to show a loading message (provided by jquerymobile) and then hide it once the image loads.

Where #gallery_image_large is the actual <img> where the src is changing, I tried the following:

$("#gallery_image_large").bind("load", function () {
   $.mobile.pageLoading(true); // hide jquerymobile loading message
});

This works in Safari on my desktop but does not in the iPhone Simulator mentioned above.

For reference:

UPDATE: I am experimenting with JQuery Image load fails on MobiOne iPhone simulator, which explains how to implement the .load manually by "checking .complete".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

欢你一世 2024-10-17 20:48:27

我改变了 jquery 的结构,它似乎已经修复了!

$('#gallery_image_large').one('load',function() {
    try { // a grade  
        $.mobile.pageLoading(true);
    } catch(err) { // low grade

    }
}).attr('src',full_src);

(如您所见,我选择了 try { .. } catch { .. } 来验证 jquerymobile 是否可用。

尽管我没有(直接)使用 JQuery 图像加载在 MobiOne iPhone 模拟器上失败,手动触发 load via .complete 对于其他人来说可能是一个很好的解决方案!

I changed the structure of my jquery and it's seemed to have fixed it!

$('#gallery_image_large').one('load',function() {
    try { // a grade  
        $.mobile.pageLoading(true);
    } catch(err) { // low grade

    }
}).attr('src',full_src);

(as you can see, I opt'd for a try { .. } catch { .. } to verify jquerymobile is available.

Although I didn't use the solution (directly) from JQuery Image load fails on MobiOne iPhone simulator, the manual firing of load via .complete is probably a good solution for anyone else out there!

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