我期望像这样的https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal_img,但在使用ng-repeat
时似乎不起作用
angular.module('selectExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.register = {
regData: {
branch: {},
},
names: [{
name:"narquois",
image:[
"https://picsum.photos/200",
"https://picsum.photos/200/300/"]
}],
};
}]);
img{
width:70px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<table id="example" width="100%">
<tr ng-repeat="person in register.names">
<td align="center">{{ person.name }}</td>
<td align="center"><img ng-repeat="image in person.image" ng-src="{{ image}}"></td>
</tr>
</table>
</div>
最佳答案
请运行以下代码。
希望它能解决您的问题。
angular.module('selectExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.register = {
regData: {
branch: {},
},
names: [{
name: "narquois",
image: [{
'image': "https://picsum.photos/200",
'flag': false
}, {
'image': "https://picsum.photos/200/300/",
'flag': false
}]
}],
};
$scope.getBig = function(key, value) {
$scope.register.names[0].image[key].flag = true;
}
$scope.close = function(key, value) {
$scope.register.names[0].image[key].flag = false;
}
}]);
.imgSmall {
width: 70px;
}
/* The Modal (background) */
.modal {
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: lightblue;
}
/* Modal Content (image) */
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
}
/* Caption of Modal Image */
#caption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}
/* Add Animation */
.modal-content,
#caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
}
@-webkit-keyframes zoom {
from {
-webkit-transform: scale(0)
}
to {
-webkit-transform: scale(1)
}
}
@keyframes zoom {
from {
transform: scale(0)
}
to {
transform: scale(1)
}
}
/* The Close Button */
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<table id="example" width="100%">
<tr ng-repeat="person in register.names">
<td align="center">{{ person.name }}</td>
<td align="center" ng-repeat="(key,image) in person.image"><img class="imgSmall" ng-src="{{image.image}}" ng-click="getBig(key,image)">
<div ng-show="image.flag" id="myModal" class="modal">
<span class="close" ng-click="close(key,image)">×</span>
<img class="modal-content" ng-src="{{image.image}}" id="img01">
<div id="caption"></div>
</div>
</td>
</tr>
</table>
</div>