jQuery 无限滚动/延迟加载

发布于 2024-08-19 22:41:55 字数 384 浏览 6 评论 0原文

我目前正在重新设计我的网站,并一直在考虑使用 JavaScript 和 jQuery。这是我到目前为止所拥有的: http://www.tedwinder.co.uk/gallery2/。

我的愿景是将所有照片放在一页上,用户可以滚动浏览,就像现在一样。但是,我了解在一页上放置 50 多个大型图像的局限性和影响,并考虑使用无限滚动和延迟加载,我知道这只会在用户访问图像或单击某个图像时加载图像。 “更多”链接?

所以,我的问题是:这会减少页面加载吗?我到底该如何实现无限滚动/延迟加载,这会有效地工作吗?或者您能想到任何更有效的方法吗?

谢谢, 特德

I'm currently redesigning my website and have been looking into using JavaScript and jQuery. Here is what I have so far: http://www.tedwinder.co.uk/gallery2/.

My vision is to have all of the photos on one page, which the user can scroll through, like now. However, I understand the limitations and effects of having 50+ large-ish images on one page and have considered using infinite scrolling and lazy loading, which I understand would only load the images when the user gets to them, or when they click on a "More" link?

So, my question is: would this reduce the page load, how exactly would I go about implementing infinite scrolling/lazy loading and would this work effectively, or could you think of any more effective way of doing this?

Thanks,
Ted

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

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

发布评论

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

评论(4

少年亿悲伤 2024-08-26 22:41:55

这是一个非常好的 jQuery 插件,可以处理图像延迟加载。

http://www.appelsiini.net/projects/lazyload

首屏下方的图像将不会加载,直到它们会滚动到视图中。

它会减少您网站的带宽,但如果您没有大量流量,则不会产生太大影响。

有关使用此技术的示例,请查看 http://mashable.com/

This is a pretty good plugin for jQuery that handles image lazy loading.

http://www.appelsiini.net/projects/lazyload

Images below the fold wont be loaded until they are scrolled into view.

It will cut down on the bandwidth of your site, but if you dont have a lot of traffic it wont make much of a difference.

For an example of this technique in use, check out http://mashable.com/

心作怪 2024-08-26 22:41:55

试试这个 jQuery 延迟滚动加载插件
http://code.google.com/p/jquerylazyscrollloading/

try this jQuery Lazy Scroll Loading Plugin
http://code.google.com/p/jquerylazyscrollloading/

表情可笑 2024-08-26 22:41:55

您可以尝试我编写的这个 jQuery 插件,它使用 html 注释来延迟加载 html 的任意位,包括图像:

jQuery 延迟加载器博客文章

jQuery 延迟加载器插件页面

这是一个示例:

<pre class=”i-am-lazy” ><!–
    <img src=”some.png” />
 –></pre>

<pre class=”i-am-lazy” ><!–
    <div>Any, html css img background, whatever. <img src=”some.png” /> </div>
–></pre>

<script type=”text/javascript” src=”jquery.lazyloader.js” ></script>
<script type=”text/javascript” >
$(document).ready( function()
{
    $(’pre.i-am-lazy’).lazyLoad();
});
</script>

基本上,您可以使用占位符标记和内部 html 注释来包装要延迟加载的内容。当占位符在视口中可见时,它会被注释内的 html 字符串替换。

您可以使用任何标记作为占位符,但我喜欢 pre,因为当里面只有注释时它会呈现为 0 维度。

希望这有帮助!
@MW_柯林斯

You can try this jQuery plugin I wrote that uses html comments to lazy load any arbitrary bits of html, including images:

jQuery Lazy Loader Blog Post

jQuery Lazy Loader Plugin Page

Here's an example:

<pre class=”i-am-lazy” ><!–
    <img src=”some.png” />
 –></pre>

<pre class=”i-am-lazy” ><!–
    <div>Any, html css img background, whatever. <img src=”some.png” /> </div>
–></pre>

<script type=”text/javascript” src=”jquery.lazyloader.js” ></script>
<script type=”text/javascript” >
$(document).ready( function()
{
    $(’pre.i-am-lazy’).lazyLoad();
});
</script>

So basically you wrap the content you want to lazy load with a placeholder tag and and inner html comment. When the placeholder becomes visible in the viewport, it is replaced with the html string inside the comment.

You can use any tag for the placeholder but I like pre because it renders as 0 dimension when there's only a comment inside.

Hope this helps!
@MW_Collins

迷乱花海 2024-08-26 22:41:55

这里还有两个执行延迟加载/无限滚动的 JQuery 插件:

http://jscroll.com/

http://www.infinite-scroll.com/infinite-scroll-jquery-plugin/

Here's two more JQuery plugins that do lazy loading / infinite scroll:

http://jscroll.com/

http://www.infinite-scroll.com/infinite-scroll-jquery-plugin/

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