打开漂亮的照片(多张图片)在按钮点击



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

这是我使用的代码。在此$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);
});

最新更新