문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top