如何使用ng-repeat全屏查看图像? [英] How to view the image in fullscreen using ng-repeat?

查看:40
本文介绍了如何使用ng-repeat全屏查看图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期望这样的东西 https://www.w3schools.com/howto/tryit.asp?filename = tryhow_css_modal_img ,但在使用 ng-repeat

I'm expecting something like this https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal_img but it seems to not work when using 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>

推荐答案

请运行以下代码.我希望它能解决您的问题.

Please run below code. I hope it will solve your problem.

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)">&times;</span>
          <img class="modal-content" ng-src="{{image.image}}" id="img01">
          <div id="caption"></div>
        </div>
      </td>
    </tr>
  </table>

</div>

这篇关于如何使用ng-repeat全屏查看图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆