What's a better method for triggering a load() event on cached images?

假装没事ソ 提交于 2019-12-10 13:33:49

问题


I'm working on a script that waits for content to load in a hidden div before activating a thumbnail that points to it.

$('#preload img:first-child')
.bind('load',activateThumb)
.each(function(){
    if(this.complete || this.complete===undefined) $(this).load()});

The each part triggers the load() event for images in the cache. I had to add it in order to make the page work in some browsers that don't fire load() on cached images.

There is also a plugin here that does the same thing essentially, by triggering the load event not "manually" but by resetting the src attribute.

From a programming standpoint, which is the more graceful solution?


回答1:


Resetting the src attribute to fire the load handler seems like a bit of a hack (based on my knowledge). Unless the author of the plugin has some special reason to do that, or knows something we don't, I would stick with your method of manually triggering load.




回答2:


The plugin event.special.load, which is mentioned in the jquery load-event documentation, solves that in a similar way.



来源:https://stackoverflow.com/questions/3554185/whats-a-better-method-for-triggering-a-load-event-on-cached-images

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