【发布时间】:2016-03-29 02:49:30
【问题描述】:
我已经用 AngularJS、bootstrap 和 Wordpress 构建了一个网站。
图库应该能够在一行中并排显示两张纵向图像,并在一行中显示横向图像。我偶然发现这篇文章http://codepen.io/horne3754sg/pen/vNBdgB 有人在图像数组中找到对并建立一个网格,但他没有使用 Bootstrap。
我希望画廊在某个断点处进入堆栈模式,但在本示例中并非如此。我面临的另一个问题是,在上面的示例中,他使用预定义的图像数组,我使用异步请求来检索我的图像,所以我无法在我的图像数组中找到对。到目前为止,这是我的代码:
AngularJS:
return $http.get('wp-json/wp/v2/projects/?status=publish&slug=' + url).success(function(res) {
WPService.project = res;
// We retrieve all sizes for each image in the project
let project_attached_images_length = WPService.project[0].attached_images.length;
for(let i=0; i< project_attached_images_length; i++) {
$http.get('wp-json/wp/v2/media/' + WPService.project[0].attached_images[i].ID).success(function(res) {
WPService.project_images[i] = res;
let image = new Image();
image.src = WPService.project_images[i].source_url;
WPService.project_images[i].width = image.width;
WPService.project_images[i].height = image.height;
if(WPService.project_images[i].width <= WPService.project_images[i].height)
WPService.project_images[i].orientation = 'portrait';
else
WPService.project_images[i].orientation = 'landscape';
//console.log(i + ' ' + WPService.project_images[i].source_url + ' ' + WPService.project_images[i].dimension);
//console.log(WPService.project_images[i]);
});
}
});
}
HTML 代码:
<div ng-repeat="project in data.project">
<div class="row" ng-repeat="image in project.attached_images track by $index" ng-hide="$index == 0">
<div ng-class="{ 'col-md-1': !isToggled, 'col-md-0': isToggled }"></div>
<div ng-class="{ 'col-md-10': !isToggled, 'col-md-12': isToggled }">
<div class="project-image afkl-lazy-wrapper afkl-img-ratio-1-1" afkl-lazy-image="{{ data.project_images[$index].media_details.sizes.medium.source_url }} 640w, {{ data.project_images[$index].media_details.sizes.large.source_url }} 768w, {{ image.guid }}"></div>
<p class="project-photos-excerpt">{{ image.post_excerpt }} - {{ data.project_images[$index].orientation }}</p>
</div><!-- .col-md-10 -->
<div ng-class="{ 'col-md-1': !isToggled, 'col-md-0': isToggled }"></div>
</div><!-- .row -->
</div><!-- ng-repeat wrapper -->
也许有人找到了另一种解决方案,例如 Masonary? (我刚遇到这个)
如何在网格中并排显示肖像图像?数组也没有固定的顺序。
【问题讨论】:
标签: html angularjs twitter-bootstrap