[英]How to add light box(photoswipe) to freewall flex grid layout photos
favorite I am currently working on a photography portfolio and I am using the Freewall dynamic grid layout for showing the photos. 最喜欢的是我目前正在从事摄影作品集,并且正在使用Freewall动态网格布局显示照片。 http://vnjs.net/www/project/freewall/
http://vnjs.net/www/project/freewall/
Specifically using this plugin: http://vnjs.net/www/project/freewall/example/flex-grid.html 具体使用此插件: http : //vnjs.net/www/project/freewall/example/flex-grid.html
This grid is great, but I really want to add a lightbox so that the user can click on each photo and look closer and also use the arrow keys to look at the other photos. 这个网格很棒,但是我真的想添加一个灯箱,以便用户可以单击每张照片并靠近它,还可以使用箭头键查看其他照片。
This is the script I am using for the grid: 这是我用于网格的脚本:
var temp = "<div class='brick' style='width:{width}px;'><img src='../i/photos/{index}.jpg' width='100%'></div>";
var w = 1, h = 1, html = '', limitItem = 8, html1='';
for (var i = 0; i < limitItem; ++i) {
w = 1 + 3 * 0.255;
html += temp.replace(/\{width\}/g, w*150).replace("{index}", i + 1);
}
$("#freewall").html(html);
var wall = new Freewall("#freewall");
wall.reset({
selector: '.brick',
animate: true,
cellW: 150,
cellH: 'auto',
onResize: function() {
wall.fitWidth();
}
});
var images = wall.container.find('.brick');
images.find('img').load(function() {
wall.fitWidth();
});
Upon some few trials and errors I found the answer; 经过几次试验和错误,我找到了答案。
This is what I added to the script: 这是我添加到脚本中的内容:
var temp = "<div class='brick' style='width:{width}px;'><img src='../i/photos/{index}.jpg' class='example-image' width='100%'/></div>";
var w = 1, h = 1, html = '',limitItem = 8;
for (var i = 0; i < limitItem; ++i) {
w = 1 + 3 * 0.255;
html += temp.replace(/\{width\}/g, w*150).replace("{index}", i + 1);
}
$("#freewall").html(html);
/************** CODE ADDDED ***********************/
for(var i = 0; i < 8; i++){
$(".example-image").eq(i).wrap("<a href='../i/photos/"+(i+1)+".jpg' data-lightbox='images'></a>");
console.log($(".example-image").eq(i));
}
/***************************************************/
var wall = new Freewall("#freewall");
wall.reset({
selector: '.brick',
animate: true,
cellW: 150,
cellH: 'auto',
onResize: function() {
wall.fitWidth();
}
});
var images = wall.container.find('.brick');
images.find('img').load(function() {
wall.fitWidth();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.