【问题标题】:How to apply other css class if first css class is not there?如果第一个 css 课程不存在,如何申请其他 css 课程?
【发布时间】:2016-03-23 14:44:57
【问题描述】:

我正在使用图像精灵。一些图像精灵 CSS 类:

.icon-ONE {
  background-image: url(../img/spritesheet.png);
  background-position: -32px 0px;
  width: 32px;
  height: 32px;
}
.icon-TWO {
  background-image: url(../img/spritesheet.png);
  background-position: -288px -288px;
  width: 32px;
  height: 32px;
}
.icon-NOIMAGE {
  background-image: url(../img/spritesheet.png);
  background-position: 0px -32px;
  width: 32px;
  height: 32px;
}

HTML:

 <div ng-repeat="product in products">
      <div ng-show="product.type!=''" class="icon-{{product.type | removeSpace | uppercase}} " ></div>
      <div ng-show="!product.type || product.type==''" class=" icon-NOIMAGE" ></div>
 </div>

所以,如果“product.type”不同,它应该应用类 icon-NOIMAGE。

我尝试过使用 ng-class this 但它不起作用。因为它们没有条件检查。需要查找是否存在 css 类。 试过了:

angular.element(myElement).hasClass('my-class');

解决方案之一:通过添加 icon-NOIMAGE 类。但在某些情况下它失败了。

 <div ng-show="product.type!=''" class="icon-{{product.type | removeSpace | uppercase}} icon-NOIMAGE" ></div>

他们有什么方法可以检查 css 类是否存在。?

他们有什么不同的方法吗,我能做到吗..?

【问题讨论】:

    标签: angularjs ionic-framework ionic css-sprites sprite-sheet


    【解决方案1】:

    如果你想有条件地应用类,你应该使用 ng-class。

    ng-class="{'yourclass' : variable == 'value'}"
    

    【讨论】:

    • 你能把你的答案应用到我的问题上吗..?解释更多..!我已经尝试过 ng-class..!
    猜你喜欢
    • 2016-01-26
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 2021-12-23
    相关资源
    最近更新 更多