JQuery Image load fails on MobiOne iPhone simulator

社会主义新天地 提交于 2019-12-12 03:49:16

问题


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

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

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

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

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?


回答1:


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();
            });


来源:https://stackoverflow.com/questions/3256306/jquery-image-load-fails-on-mobione-iphone-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!