YUI 图像加载器折叠上方的图像直到滚动事件才加载

发布于 2024-08-28 19:07:12 字数 580 浏览 4 评论 0原文

我有一个在 window.onload 事件上调用的函数来创建一组图像并通过滚动事件进行渲染。

function LoadImages(){  
    var foldGroup = new YAHOO.util.ImageLoader.group(window, 'scroll'); 
    for(var i=0; i<someCounter; i++){
        var locationId = locationsArr[i];
        foldGroup.registerSrcImage('Location_' + locationId, GetImageDomain()+'/templates/Includes/imagehandler.ashx?locationId=' + locationid);
    }
    foldGroup.foldConditional = true; 
    foldGroup.addTrigger(window, 'resize');
}

我遇到的问题是,当页面加载时,“首屏”的图像在滚动之前不会呈现。有解决此问题的任何提示吗?我完全不是 js/前端人员:)

提前致谢!

I have a function that is called on the window.onload event to create a group of images and render via the scroll event.

function LoadImages(){  
    var foldGroup = new YAHOO.util.ImageLoader.group(window, 'scroll'); 
    for(var i=0; i<someCounter; i++){
        var locationId = locationsArr[i];
        foldGroup.registerSrcImage('Location_' + locationId, GetImageDomain()+'/templates/Includes/imagehandler.ashx?locationId=' + locationid);
    }
    foldGroup.foldConditional = true; 
    foldGroup.addTrigger(window, 'resize');
}

The problem I'm having is that when the page loads, the images "above the fold" are not rendered until I scroll. Is there any tips on troubleshooting this? I'm totally not a js/frontend guy :)

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

记忆里有你的影子 2024-09-04 19:07:12

由于 ImageLoader 实用程序使用页面加载来检查图像位置,因此您需要在该点之前创建组并注册图像。正如您所发现的,要么是内联的,要么是在 DOM 准备好的时候,如 Tivac 所建议的。

对 ImageLoader 进行了更改来解决此问题,但直到下一个 YUI 2 版本才可用。您可以在这里关注 - http://yuilibrary.com/projects/yui2/ticket/2527646< /a>

Since the ImageLoader utility uses page load to examine image positions, you need to create your group and register images before that point. Either inline, as you've discovered, or at DOM ready time, as Tivac suggests.

There is a change to ImageLoader to address this issue, though it won't be available until the next YUI 2 release. You can follow it here - http://yuilibrary.com/projects/yui2/ticket/2527646

落日海湾 2024-09-04 19:07:12

我只是尝试了这个内联,效果很好:

<script type="text/javascript">
var foldGroup = new YAHOO.util.ImageLoader.group(window, 'scroll'); 
for(var i=0; i<someCounter; i++){
    var locationId = locationsArr[i];
    foldGroup.registerSrcImage('Location_' + locationId, GetImageDomain()+'/templates/Includes/imagehandler.ashx?locationId=' + locationid);
}
foldGroup.foldConditional = true; 
foldGroup.addTrigger(window, 'resize');</script>

如果有人有更好的答案,我肯定会感兴趣。

I just tried this inline instead and it worked fine:

<script type="text/javascript">
var foldGroup = new YAHOO.util.ImageLoader.group(window, 'scroll'); 
for(var i=0; i<someCounter; i++){
    var locationId = locationsArr[i];
    foldGroup.registerSrcImage('Location_' + locationId, GetImageDomain()+'/templates/Includes/imagehandler.ashx?locationId=' + locationid);
}
foldGroup.foldConditional = true; 
foldGroup.addTrigger(window, 'resize');</script>

In case anyone has a better answer, I'd definitely be interested.

放我走吧 2024-09-04 19:07:12

不要使用 window.onload。如果您已经在使用 YUI 2,我建议包括 Event 模块并设置您的 ImageLoader onDOMReady< /a>.如果没有看到有问题的页面,我真的不能说这是否是你的问题,但它肯定会让你在未来免于头痛。

Don't use window.onload. If you're already using YUI 2 I suggest including the Event module and setting up your ImageLoader onDOMReady. Without seeing the page in question I can't really say if that was your problem or not but it will definitely save you from headaches in the future.

第七度阳光i 2024-09-04 19:07:12

尝试一下这个插件 jQuery 异步图像加载器,并告诉我它是否适合您。

Try to have a go to this plugin jQuery Asynchronous Image Loader and let me know if it suits you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文