将不透明度设置为除选定图块之外的所有图块

时间:2016-07-25 18:13:57

标签: javascript html angularjs

我注意到有几个问题与这个类似,但不完全一样。我正在使用ng-repeat来显示我拥有的所有上传图片。我可以点击一个,它将成为默认图片。我希望点击的图像看起来正常,而其他所有图像都有overlay。我尝试在$('overlay').hide()函数中设置selectImage,但这只会在第一张图片上从我的HTML中删除叠加层。关于如何做到这一点的任何想法?

HTML

<!-- PHOTOS -->
      <div class="uploads-section" style="width: 100%;">
        <md-grid-list md-cols="3" md-row-height="1:1" md-gutter="8px" style="padding-top: 10px;">
          <md-grid-tile md-rowspan="1" md-colspan="1">
            <div style="background-color: #3F454b; padding: 30px; cursor: pointer; height: 100%; width: 100%;" class="upload-tile no-outline" layout="column" layout-align="center start" ng-click="uploadImage('photo')">
              <md-icon style="color: #FFFFFF; width: 40px; height: 40px;" md-svg-icon="images/upload.png"></md-icon>
              <p class="action-link" style="margin: 0; color: #FFFFFF;">UPLOAD</p>
            </div>
          </md-grid-tile>
          <md-grid-tile ng-repeat="photo in org.attachments | filter:{type:'photo'}" md-rowspan="1" md-colspan="1" style="opacity: .5;">
            <div style="width: 100%; height: 100%; position: relative; overflow: hidden;" class="attachment-tile no-outline" layout="row" layout-align="center center" ng-click="selectImage($event, photo)">
              <!-- <p class="m1">Loading...</p> -->
              <img attachment-src="{{ photo.path | ThumbnailFilter }}" default-src="images/no_img.png" style="cursor: pointer; height: 100%; width: 100%; object-fit: cover;">
            </div>
          </md-grid-tile>
          <md-grid-tile ng-repeat="photo in org.defaultOrgImages | filter:{type:'photo'}" md-rowspan="1" md-colspan="1">
            <div style="width: 100%; height: 100%; position: relative; overflow: hidden;" class="attachment-tile no-outline" layout="row" layout-align="center center" ng-click="selectImage($event, photo)">
              <!-- <p class="m1">Loading...</p> -->
              <img attachment-src="{{ photo.path | ThumbnailFilter }}" default-src="images/no_img.png" style="cursor: pointer; height: 100%; width: 100%; object-fit: cover;">
              <div id="overlay"></div>
            </div>
          </md-grid-tile>
        </md-grid-list>
      </div>

CONTROLLER

$scope.selectImage = function (ev, attachment) {
  if (attachment.type == 'photo' && attachment.path != $scope.org.defaultPhoto) {
    $scope.org.defaultPhoto = attachment.path;
    saveOrg();
  }
};

LESS

 #overlay {
    position: relative;
    cursor: pointer;
    height: 100%;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.4);
 }

1 个答案:

答案 0 :(得分:1)

我想说最简单的方法是在CSS / LESS文件中创建一个类,如下所示:

.faded {
  opacity: 0.5;
}

然后你所要做的就是将faded追加到你想要褪色的img的类值。

这通常是改变多个元素的不透明度的最佳和最简单的方法。