javascript - 单击按钮打开漂亮的照片(多张图片)

标签 javascript php jquery html css

我正在使用 prettyphoto,因为我可以通过单击按钮打开单个图像作为 prettyphoto。但我需要在单击按钮时将多个图像打开为漂亮的照片。

这是我使用的代码。在这个 $image_src_cb1 中是一个数组。

<?php $html .= $button_class_wrapper_open . "<a class='" . $button_class . $button_animation_class . $prettyphoto_class . "' data-rel='" . $pretty_photo_rel . "' href='" . $image_src_cb1 . "' ><span class='cover_boxes_button_text text_wrap'> " . $link_label1 .'</span>'. $button_icon . "<span class='a_overlay'></span></a>" . $button_class_wrapper_close;

谁能给我建议在单击按钮时打开多个图像。

最佳答案

使用版本:3.1.5

为每个图像添加一个标识符。例如 rel 属性:

<img src="image--1.jpg" rel="prettyPhoto[myGallery]" alt="">
<img src="image--2.jpg" rel="prettyPhoto[myGallery]" alt="">
<img src="image--3.jpg" rel="prettyPhoto[myGallery]" alt="">

<button type="button" class="foo">Gallery</button>

将 src 属性作为数组传递给 prettyPhoto:

$('.foo').on('click', function() {
    var ImgArr = [];

    $('[rel="prettyPhoto[myGallery]"]').each(function() {
        var src = $(this).attr('src');
        ImgArr.push(src);
    });
    $.prettyPhoto.open(ImgArr);
});

关于javascript - 单击按钮打开漂亮的照片(多张图片),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46931945/

相关文章:

javascript - Handlebars - 获取未更改的 block 内容

javascript - 如何在 javascript 和 HTML 中声明全局变量?

javascript - 如何使用 form.$addControl()

php - 当我转换时,网站可以是 mysql 和 mysqli 的一部分吗

php - Windows 上的 WGET 通过 PHP exec() 不起作用

jQuery,使下拉菜单在单击其他地方时隐藏

javascript - JS Discord 机器人获取角色

PHP - 使用循环重新排序

javascript - 如何传递参数jquery并返回函数值

javascript - jquery只能通过拖动标题进行排序