首页 > 解决方案 > 单击即可在 Galleria 中交换图像

问题描述

我有一个图片库来展示我正在开发的游戏的屏幕截图,我想对这些图片进行前后处理。我希望所有后图像正常显示为画廊默认设置。对于之前的图像,虽然我希望它们在单击时显示在相应的后图像上,而不是所有的图像都只是单击。我希望这是一个切换,以便他们可以单击以在新旧版本之间来回切换以进行比较。

标签: galleria

解决方案


纳米,想通了。我在 Galleria.run 函数中使用了它。

                    extend: function(options) {

                    Galleria.log(this) // the gallery instance
                    Galleria.log(options) // the gallery options

                    // listen to when an image is shown
                    this.bind('image', function(e) {

                        Galleria.log(e) // the event object may contain custom objects, in this case the main image
                        Galleria.log(e.imageTarget) // the current image

                        // lets make galleria open a lightbox when clicking the main image:
                        $(e.imageTarget).click(this.proxy(function() {
                            //this.openLightbox();
                            if (e.imageTarget.src.includes("Old")) {
                                e.imageTarget.src = e.imageTarget.src.replace("-Old.png", ".png");
                            } else {
                                e.imageTarget.src = e.imageTarget.src.replace(".png", "-Old.png");

                            }
                            //e.imageTarget.src = "../images/Games/TheVoid/MenuScreen-Old.png";
                        }));
                    });
                }

您当然可以将其调整为不同的东西,但这就是我的做法。


推荐阅读