【发布时间】: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