jQuery.Cycle 在第一次加载时显示小图像
我的 jQuery.cycle 插件有问题。第一次加载页面时(当未缓存图像时),它显示小图像,例如缩略图。您可以在(编辑:抱歉,旧链接)看到它 - 只需等待第二张图片显示即可 - 它很小。重新加载/刷新可以解决这个问题,但这不是真正的解决方案,你知道。
有谁知道这个问题的解决方案是什么?多谢
I've got problem with jQuery.cycle plugin. At first load of page (when imgs aren't cached) it's showing small imgs, like thumbnails. You can see it at (edit: sorry, old link) - just wait when the second img shows - it's small. Reload/refresh solves it, but it's not real solution, you know.
Does anybody know what's the solution of this problem? Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我遇到了同样的问题,这让我发疯!我尝试预加载图像,检查所有内容的版本等,但无济于事。似乎解决此问题的唯一方法是在页面上的每张图片上设置宽度和高度,而不是在 CSS 中。
I had the same issue and it was driving me crazy! I tried pre-loading the images, checked versions on everything etc to no avail.. The only thing that seemed to fix this was setting width and height on each picture on the page, rather than in css.
我通过在
标记中设置宽度和高度解决了这个问题。但由于我使用脚本来生成图像列表,并且它们有时具有不同的大小,所以我使用了一点 php 来解决这个问题:
例如,
$imgsize[3]
是,宽度=“585”高度=“285”
。然后,在幻灯片中显示目录中的所有 jpg:
输出
I solved this by setting the width and height in the
<img>
tag. But since I'm using a script to generate the list of images, and they sometimes have various sizes, I used a tiny bit of php to solve this:$imgsize[3]
is, for example,width="585" height="285"
.And then, to show all jpgs in the directory in the slideshow:
Output
由于浏览器端的逻辑错误,导致 24px 出现 - 过早返回占位符控件的尺寸。它们具有不同的控制逻辑来处理缓存图像,IE 甚至不会为它们触发
onload
,这就是出现所有混乱的原因。比
(width===0)
检查是否加载图像在整个互联网上找到更可靠,.complete
DOM 属性很少被提及,显然受到所有主要支持浏览器: http://www.w3schools.com/jsref/prop_img_complete.asp这个为我工作:
.complete
测试应该解决 24px 占位符控件逻辑错误的情况,即.one('load').each()
。涵盖缓存/远程上的控制流分割。The 24px come up due to faulty logic on browser side - returning prematurely dimensions for a placeholder control. They have a different control-logic for handling cached images, IE does not even trigger
onload
for them, and that's why all the confusion comes up.More reliable than
(width===0)
checking to be found all over the internet if an image is loaded, the.complete
DOM property seldom mentioned apparently supported by all major browsers: http://www.w3schools.com/jsref/prop_img_complete.aspthis worked for me:
the
.complete
test should solve the case of the faulty 24px placeholder control's logic, the.one('load').each()
. covers the control-flow split on cached/distant.使用
$(window).load(function() { });
而不是$(document).ready(function() { });
Use
$(window).load(function() { });
rather than$(document).ready(function() { });
在图像容器
DIV
上使用overflow:hidden
Use
overflow:hidden
on the images containerDIV
同样的问题。随机图像的内联样式为 24px x 24px。我没有设置每个图像的高度和宽度,而是通过 CSS 来设置。由于我的宽度是固定宽度,所以我设置了它,但将高度设置为 100%:
!important 对于覆盖 jQuery 循环应用的内联样式是必要的。
这似乎也解决了我在 IE8 中遇到的另一个问题。页面可以正常加载,但图像似乎是在加载所有 CSS 和 jquery 之后才加载的。这导致该框无法扩展以适应其中图像的高度和宽度。我想象设置宽度和高度,保存图像的盒子立即调整大小。
Same issue. Random images were getting inline styles of 24px x 24px. Rather than setting each image height and width, I did so through CSS. Since my width was a fixed width, I set that but set the height to 100%:
The !important is necessary to override the inline styles applied by jQuery cycle.
This also seemed to solve another issue I was having with IE8. The page would load fine, but the images seemed to be loading after all the CSS and jquery loaded. This caused the box to not expand to fit the height and width of the images within. I imagine setting the width and height, the box holding the images was sized right off the bat.