iPhone模拟器上的JQuery图像加载失败

iPhone模拟器上的JQuery图像加载失败

本文介绍了MobiOne iPhone模拟器上的JQuery图像加载失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我使用以下代码动态更新JQTouch站点上的图像:

I dynamically update an image on a JQTouch site using the following code:

  $('#sv_map')
            .one('load', function() {
                $(this).fadeIn();
            })
            .attr('src', imgURL);

此处了解了这一基础. sv_map是图像,imgURL指向有效的现有JPG文件.

Got the basics of this from here. sv_map is an image, and imgURL points to a valid, existing JPG file.

此代码可在所有主流浏览器(Chrome,Safari,Firefox,IE)以及实际设备(多个iPhone和iPod)上正常运行.

This code works as expected on all major browsers (Chrome, Safari, Firefox, IE) as well as on actual devices (several iPhones and iPods).

我不想断定模拟器存在错误(似乎是个小问题).需要什么其他代码来确保加载图像文件?有人在MobiOne上有过类似的经历吗?

I don't want to conclude that the simulator has a bug (it seems like such a trivial issue). What additional code is needed to ensure that the image file gets loaded? Has anyone had a similar experience with MobiOne?

推荐答案

并非所有浏览器都会正确触发load事件(尤其是从缓存加载时),因此您需要通过在图像,像这样:

Not all browsers fire the load event correctly (especially when loading from cache), so you'll need to do it manually by checking .complete on the image, like this:

  $('#sv_map').one('load', function() {
               $(this).fadeIn();
            }).attr('src', imgURL)
              .each(function() {
               if(this.complete) $(this).load();
            });

这篇关于MobiOne iPhone模拟器上的JQuery图像加载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:21