具有 AJAX 功能的 jQuery 循环插件

发布于 2024-10-20 02:54:46 字数 264 浏览 2 评论 0原文

我有一个页面,其中有多个图片滑块(例如 50 个滑块+,每个滑块有 5-10 张图片)。不幸的是,由于滑块数量巨大,页面加载速度非常慢:- (

到目前为止,我一直在使用 Malsup 著名的 jQuery Cycle 插件。但是,这缺乏 AJAX 功能,因为需要在启动循环之前加载图片 ?

我有半经验,但没有时间编写适合我需要的库,

因此问题是,有人了解 Jquery 滑动(Ajax 加载)图片插件吗 但有太多的数据压倒了真实的结果..

提前致谢!

I have a page where I'll have multiple picture sliders (like 50 sliders+ with 5-10 pictures each). Unfortunately because of this massive amount of sliders, the page loads really slow :- (

Until now I've been using the famous jQuery Cycle Plugin by Malsup. However, this lacks AJAX functionality, as the picture's needs to be loaded before firing the cycle function.

I'm semi experienced, but lacking the time to write my own libary suiting my needs.

Hence the question, does anyone have knowledge of a Jquery sliding (Ajax loading) picture plugin? I've been searching all over the web, but there's too much data overwhelming the real results..

Thanks in advance!

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

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

发布评论

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

评论(1

心清如水 2024-10-27 02:54:46

这是一种黑客攻击,但可能对您有用,滑块插件支持前后功能,我们可以利用该功能来为您推迟图像的加载。

给出以下标记:

<div id="s1" class="pics">
    <img src="http://cloud.github.com/downloads/malsup/cycle/beach1.jpg" width="200" height="200" />
    <img src="http://cloud.github.com/downloads/malsup/cycle/beach2.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach3.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach4.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach5.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach6.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach7.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach8.jpg" width="200" height="200" />
</div>

请注意,前两个具有有效的 src attr,但其余的是 asrc,它不是通过浏览器加载的。

现在,通过 before 和 after 函数,我们可以利用它并将 asrc 切换到真正的 src,这将导致浏览器查询图像。

$('#s1').cycle({
    fx: 'shuffle',
    speed: 'fast',
    timeout: 0,
    next: '#next2',
    prev: '#prev2',
    before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
        if ($(nextSlideElement).attr("asrc")) {
            $(nextSlideElement).attr("src", $(nextSlideElement).attr("asrc"));
        }
    },
    after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
        if ($(nextSlideElement).attr("asrc")) {
            $(nextSlideElement).attr("src", $(nextSlideElement).attr("asrc"));
        }
    }
});

jsfiddle 上的示例。

This is sort of a hack but might be able to work for you, the slider plugin supports a before and after function which we can take advantage of to defer the loading of the images for you.

given the following markup:

<div id="s1" class="pics">
    <img src="http://cloud.github.com/downloads/malsup/cycle/beach1.jpg" width="200" height="200" />
    <img src="http://cloud.github.com/downloads/malsup/cycle/beach2.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach3.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach4.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach5.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach6.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach7.jpg" width="200" height="200" />
    <img asrc="http://cloud.github.com/downloads/malsup/cycle/beach8.jpg" width="200" height="200" />
</div>

Notice the first two have valid src attr, but the rest are asrc which is not loaded via the browser.

Now with the before and after function we can take advantage of that and switch the asrc to a real src which will cause the browser to query for the image.

$('#s1').cycle({
    fx: 'shuffle',
    speed: 'fast',
    timeout: 0,
    next: '#next2',
    prev: '#prev2',
    before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
        if ($(nextSlideElement).attr("asrc")) {
            $(nextSlideElement).attr("src", $(nextSlideElement).attr("asrc"));
        }
    },
    after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
        if ($(nextSlideElement).attr("asrc")) {
            $(nextSlideElement).attr("src", $(nextSlideElement).attr("asrc"));
        }
    }
});

Example of this on jsfiddle.

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