就是在ng-click中動態更改樣式,請問有什麼想法或方法嘛?急急! !線上等! ! !拜託了各位大神! !
给我你的怀抱2017-05-15 17:06:32
提供一個簡單思路:
JS:
$scope.isActive = 0;
$scope.arr = [
{
//code here
},
{
//code here
}
];
$scope.selectItem = function (index) {
item.isActive = index;
}
HTML:
<ul>
<li ng-repeat="item in arr track by $index" ng-class="{red:isActive === $index, black:!isActive === $index}" ng-click="selectItem($index)"></li>
</ul>
CSS:
.red {
background: red;
}
.black {
background: black;
}
修改你的程式碼就是這樣:
HTML:
<p class="p10 c-white w50p fl mr1 tc" ng-repeat="e in item.images">
<p class="w50p h50 img_p" ng-class="{b-red:isActive === $index,b-white:!isActive === $index}" ng-click="changeGood($index)">
<img src="{{e.path}}">
</p>
<span class="ib w50p fs0-6 span-over">{{e.description}}</span>
</p>
controller:
$scope.isActive=0;
$scope.changeGood=function(index){
$scope.isActive=index;
}
PHP中文网2017-05-15 17:06:32
我之前回答過另一個人提出的和你類似的問題,我直接把之前寫的demo改一改發給你了,完全符合你的要求,你預覽下,如果看不到效果就要翻下牆,demo如下:
Demo