.load() does not work on ipad

风流意气都作罢 提交于 2019-12-02 03:48:51
Parv Sharma

It is mentioned on the jQuery official website:

Caveats of the load event when used with images

A common challenge developers attempt to solve using the .load() shortcut is to execute a function when an image (or collection of images) have completely loaded. There are several known caveats with this that should be noted. These are:

  • It doesn't work consistently nor reliably cross-browser
  • It doesn't fire correctly in WebKit if the image src is set to the same src as before
  • It doesn't correctly bubble up the DOM tree
  • Can cease to fire for images that already live in the browser's cache

As said by @Parv-sharma, .load is not reliable. Same experience here.

If this is about stuff like responsive image adjustment (just guessing), this is IMHO your best chance of workaround:

  1. have a central resizeScript() of course. Make sure you catch the img.height() === 0 case, in that case stick with your graceful degradation aka default aka non-js scaling. (read: do nothing for now)

  2. fire your resizeScript() up to three times

    on image.load(), on jQuery.ready() and lastly a delayed one, a few milliseconds later.

    setTimeout( App.adjustFullsize ,300);
    

    That either does no harm (if one of the prior calls did the job already, or if things keep failing) but has a good change that image is now also “officially” loaded...

(oh, there's a 4th time, you probably want to register to the resize() (i.e. device turns) event as well...).

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