Fade image onload but not for cache

与世无争的帅哥 提交于 2019-12-08 04:54:47

问题


I want to fade-in images on my page when they load, but if this image is not already in cache - just show it normally. I've tried inline html

<img onload="$(this).show(500)" />

and css img{display:none}, but it fires even if this image is already in cache. How do I fade-in only images, which are not in cache?


回答1:


This should work in all relevant browsers.

On domready, the cached image will be complete already, thus the onload handler is not set.

$('img.fadeuncached').each(function() {
    if(!this.complete) {
        var $el = $(this);
        $el.load(function() { $el.fadeIn(500); });
    }
});


来源:https://stackoverflow.com/questions/19755933/fade-image-onload-but-not-for-cache

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