点击按钮打开prettyphoto(多个图像)

时间:2017-10-25 12:03:11

标签: javascript php jquery html css

我正在使用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;

任何人都可以给我建议在按钮点击时打开多个图像。

1 个答案:

答案 0 :(得分:1)

使用版本: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);
});