加载时图像淡入的问题
随着最近情况变得明朗,我再次开始处理我的投资组合。它仍然很新鲜,但我可以使用图像的 jquery .load() 的一些帮助。
http://progress.patrikarvidsson.com/
我正在使用 jQuery 和 html5boilerplate;除此之外,我还有 Masonry 和 Lightbox。我不怀疑灰度代码是罪魁祸首,所以我不会将其包含在这里。下面是我的 script.js 文件的顶部(在灰度代码之后)。
$(window).load(function() {
$(".thumb img").bind("load", function () { $(this).fadeIn('slow'); });
Html 看起来像这样(结构仍然遵循 html5boilerplate。JS 文件在后面,但 Modernizr 在前面)
<div class="block">
<a href="titlehighres.jpg" class="thumb" title="title"><img src="img/thumbs/titleSmall.jpg" alt="" /></a>
</div>
fadeIn() 有效,但不是我想要的。首先加载图像,然后在加载文档时自动隐藏图像,然后淡入生效。如果您访问上面的链接,您可能会看到它。基本上,对我来说它看起来像这样。
Page load
Images loads with color
jQuery hides images
jQuery fadeIn desaturated images
每次我点击刷新时都会发生这种情况。请注意,这是在 Chrome 中,fadein 在 Firefox 中根本不起作用,但我还没有在我的另一台计算机上测试过。到最后我也想不出问题出在哪里。
更新
我决定改用 css3-animation。它工作得很好,但我还没有看到它在旧浏览器中的样子。
尽管如此,我仍然很好奇为什么会出现这个问题。所以仍然鼓励回答!
As things have cleared up lately, I started working on my portfolio again. It's still very fresh but I could use some help with jquery .load() of images.
http://progress.patrikarvidsson.com/
I'm using jQuery with html5boilerplate; on top of this I have Masonry and Lightbox. I don't suspect the code for the greyscale stuff is the culprit so I won't include it here. Below is the top of my scripts.js file (after the greyscale-code follows).
$(window).load(function() {
$(".thumb img").bind("load", function () { $(this).fadeIn('slow'); });
Html looks like this (structure still follows html5boilerplate. JS-files are after, but modernizr are before)
<div class="block">
<a href="titlehighres.jpg" class="thumb" title="title"><img src="img/thumbs/titleSmall.jpg" alt="" /></a>
</div>
The fadeIn() works, but not as I want it. Images are loaded first, after which they are autmatically hidden when document is loaded and then fadeIn takes effect. You can probably see it if you visit the link above. Basically, for me it looks like this.
Page load
Images loads with color
jQuery hides images
jQuery fadeIn desaturated images
This happens every time I hit refresh. Note that this is in Chrome, fadein doesn't work at all in Firefox but I haven't tested this on my other computer yet. In the end, I can't figure out what the problem is.
Update
I have decided to use css3-animation instead. It works pretty well but I am yet to see how it looks in older browsers.
Although, I'm still curious to why this issue happens. So an answer is still encouraged!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在 CSS 中隐藏彩色图像。然后它们将不会在页面加载时显示:
Try hiding the colour images in CSS. They will then not be shown on page load:
尝试在
document.ready
上将所有图像的不透明度
降低到非常低的水平——几乎看不见,但保留它们的尺寸。或者,只需通过 Javascript 隐藏图像 - 这样,无脚本查看器仍然可以看到您的图像,正如您上面提到的那样。
Try reducing the
opacity
of all your images to something really low -- ever so barely seen, but retaining their dimensions -- ondocument.ready
.Alternatively, just hide the images via Javascript -- that way, noscript viewers can still see your images, as you noted above.