自定义 jquery 画廊

发布于 2024-10-07 22:12:06 字数 255 浏览 1 评论 0原文

我正在创建一个模板。除了 jquery 图像库之外,所有 xhtml/css 工作都已完成。周围有太多的jquery画廊,我不知道如何根据情况自定义它们

这是一个三列模板..第一列有导航。第二列将从第三列的缩略图中选择图像。第三列中还有用于旋转缩略图的向上/向下按钮。单击缩略图应加载到第二列的图像 div 中。

我需要提供更多信息吗?

替代文本

I am creating a template. All xhtml/css work is done but a jquery image gallery. There are too many jquery galleries around and i do not know how to customize them according to situation

This is a three column template..First column has navigation. second column will have image selected from thumbnails of 3rd column. Also there are up/down buttons in 3rd column that rotate thumbnails. ON clicking a thumbnail image should load in 2nd column's image div.

Do i have to provide any more info?

alt text

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

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

发布评论

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

评论(2

千と千尋 2024-10-14 22:12:06

由于您实际上没有提出问题,所以我假设您是在问如何开始。您还没有给出 HTML 结构,所以我也必须假设这一点。

HTML 结构

<div id="gallery">
    <img id="main_image" />
    <div>
        <img src="image1-thumbnail.jpg" />
        <img src="image2-thumbnail.jpg" />
        <img src="image3-thumbnail.jpg" />
        <img src="image4-thumbnail.jpg" />
    </div>
</div>

首先创建一个 jQuery 插件:

(function ($) {
    $.fn.gallery = function () {

    };
})(jQuery)

这可以确保您的代码完全可重用,并且如果您将来想将其与其他框架一起使用,也不会导致命名冲突。接下来,您要向每个缩略图添加单击事件,以使其修改主图像的 SRC:

(function ($) {
    $.fn.gallery = function () {
        this.find($(this).attr('id') + '>div>img').click(function () {
            $(this).siblings('img').removeClass('selected');
            $(this).addClass('selected');
            var mainImageSrc = $(this).attr('src').replace('-thumbnail','');
            $(this).parent().siblings('img').attr('src',mainImageSrc);
        });
        return this; // jQuery plugins should (nearly) always return this to make them chainable
    };
})(jQuery);

最后调用您的函数:

jQuery(function ($) {
    $('#gallery').gallery();
});

此代码应提供基本功能。我将让您致力于使缩略图可滚动,如果您真的愿意的话,可以在图像之间进行淡入淡出(提示:您需要两个 img 标签,使用 CSS 将它们放在彼此之上,然后 .animate() 它们之间淡出的不透明度)。希望这能让你继续前进。

Since you haven't actually asked a question, I'm going to assume you're asking how to get started. You also haven't given your HTML structure, so I'm going to have to assume that too.

HTML structure

<div id="gallery">
    <img id="main_image" />
    <div>
        <img src="image1-thumbnail.jpg" />
        <img src="image2-thumbnail.jpg" />
        <img src="image3-thumbnail.jpg" />
        <img src="image4-thumbnail.jpg" />
    </div>
</div>

Start off by creating a jQuery plugin:

(function ($) {
    $.fn.gallery = function () {

    };
})(jQuery)

This ensures that your code will be completely re-usable and won't cause naming clashes if you want to use it with another framework in future. Next you want to add a click event to each thumbnail to make it modify the SRC of the main image:

(function ($) {
    $.fn.gallery = function () {
        this.find($(this).attr('id') + '>div>img').click(function () {
            $(this).siblings('img').removeClass('selected');
            $(this).addClass('selected');
            var mainImageSrc = $(this).attr('src').replace('-thumbnail','');
            $(this).parent().siblings('img').attr('src',mainImageSrc);
        });
        return this; // jQuery plugins should (nearly) always return this to make them chainable
    };
})(jQuery);

Finally call your function:

jQuery(function ($) {
    $('#gallery').gallery();
});

This code should provide the basic functionality. I'll leave you to work on making the thumbnails scrollable, and if you really feel up to it, making a fade between images (hint: you need two img tags, with CSS to lay them on top of each other, then .animate() the opacity to fade between them). Hopefully this should get you going though.

霓裳挽歌倾城醉 2024-10-14 22:12:06

Galleriffic 是您的解决方案

http://www.twospy.com/galleriffic/index.html

它非常可定制且易于集成。

Galleriffic Is Your Solution

http://www.twospy.com/galleriffic/index.html

Its very Customizable and Easy to Integrate.

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