jQuery .load() not working on my image

前端 未结 2 660
半阙折子戏
半阙折子戏 2020-12-01 00:46

I have some code I am trying to run once my image has finished loading. I use this following jQuery code:

$(\"#myimageid\").load(function() {
    alert(\'Im         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 01:27

    What happens when you clear your browser's cache and try the script again? From the jQuery load() docs:

    It is possible that the load event will not be triggered if the image is loaded from the browser cache. To account for this possibility, we can use a special load event that fires immediately if the image is ready. event.special.load is currently available as a plugin

    In general, it is not necessary to wait for all images to be fully loaded. If code can be executed earlier, it is usually best to place it in a handler sent to the .ready() method.

    So it sounds like your cached image isn't triggering the load event, so you may want to try the plug-in that's mentioned. You can find the JS file to download here.

    Hope this helps!

提交回复
热议问题