Chrome / Safari图片加载器,第一次打开

编程入门 行业动态 更新时间:2024-10-27 04:27:47
本文介绍了Chrome / Safari图片加载器,第一次打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

建立我自己的图像滑块,在Firefox内完美地工作。然而在chrome / safari中,图片往往不会在第一次打开页面时加载。 (如果你刷新一切都很好)

Built my own image slider, works perfectly inside firefox. Yet in chrome / safari the images tend to not load the first time the page is opened. (if you refresh everything is fine)

var count = $("#show-image img").size(); var img = $("#show-image img"); $(document).ready(function () { for(i=0;i<count;i++){ var width = img[i].width; var height = img[i].height; $(img[i]).css({"width": width, "height": height}); console.log(img[i].width); } });

在Chrome和Safari浏览器中,第一次加载页面时,某些图片的高度和宽度设置为0px。

In chrome and safari, the first time the page loads some of the images are getting the height and width set to 0px. I'm assuming cause the images aren't fully loaded yet.

当页面执行完全载入时,如何运行代码?

How is it possible to run the code, when page is ACTUALLY fully loaded?

推荐答案

作为一个快速简单的解决方案,使用 .load() 。

As a quick and simple solution, use .load() instead.

更好的解决方案是使用此jQuery插件:

A better solution would be to use this jQuery plugin:

$(document).ready(function() { $('#show-image').imagesLoaded(function() { /* your code here */ }); });

优点是您只需要等待加载这些特定图片, >

The advantage being that you only have to wait for those specific images to be loaded, instead of everything as you would for .load().

更多推荐

Chrome / Safari图片加载器,第一次打开

本文发布于:2023-10-12 21:39:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   图片   Chrome   Safari

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!