JS代码
body.on('click', '[layer-pid]', function () {
let currentId = $(this).attr('layer-pid');
let photosList = $(this).closest('.photos-list');
let data = {
"title": "", //相册标题
"id": photosList.attr('class'), //相册id
"start": currentId, //初始显示的图片序号,默认0
"data": [ //相册包含的图片,数组格式
]
};
console.log(data);
photosList.find('img').each(function () {
let pid = $(this).attr('layer-pid');
let src = $(this).attr('src');
data.data.push({
alt: '图片预览',
pid: pid,
src: src,
thumb: src
});
});
layer.photos({
photos: data
, anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
});
});
HTML
<div id="upload-photo" class="flex upload-have-bottom-description flex photos-list">
{% for key,img in item.images %}
<div class="sharing-icons c-img-list list_imahe">
<img layer-pid="{{ key }}" class="" src="{{ img }}">
</div>
{% endfor %}
</div>
555