angular4 数组操作div,渲染染色,大小,旋转角度

作者:LoveEmperor-王子様


HTML:

<div id= "seats" * ngIf= "parkTierBool==true" >

<div class= "carportMap" >
<img class= "carportIMG" src= "../assets/img/carportImg1.png" width= "100%" />
<div class= "carportCellMap" >
<span * ngFor= "let subCarport of carObj; let i = index" >
<div class= "seat3" name= "carInfoDIv" id= "{{subCarport.carportId}}"
style= "position: relative;vertical-align: middle;"
[ style. left. px]= subCarport.horizontal*currentWidth
[ style. top. px]= subCarport.vertical*currentheight
[ ngStyle]= "{'background-color':subCarport.reserved === 1 ? '#33FF66' :
(subCarport.used == 1 ? 'red':(subCarport.youReserved===1 ? '#33FF66':'white'))}"
[ style. width. px]= subCarport.width*currentWidth
[ style. height. px]= subCarport.height*currentheight
>{{subCarport.carportId}} </div>
</span>
</div>
</div>
</div>


ng:

this. currentWidth = window. screen. width;
this. currentheight = window. screen. height- 48;

this. carportList4 = [
{
"id" : 3,
"seat" : "1-3",
"horizontal" : "0.13",
"vertical" : "0.14",
"status" : 1,
"transform" : "7",
"width" : "0.03",
"height" : "0.04",
},
{
"id" : 4,
"seat" : "1-3",
"horizontal" : "0.16",
"vertical" : "0.14",
"status" : 1,
"transform" : "8",
"width" : "0.03",
"height" : "0.04",
},
{
"id" : 5,
"seat" : "1-3",
"horizontal" : "0.13",
"vertical" : "0.15",
"status" : 1,
"transform" : "9",
"width" : "0.05",
"height" : "0.02",
},
]

this. carportList3 =[
{
"carportId" : 1,
"seat" : "1-1",
"horizontal" : "",
"vertical" : "",
"status" : 0,
"transform" : "10deg",
"used" : 0,
"reserved" : 1,
"youReserved" : 0,
"empty" : 1
},
{
"carportId" : 2,
"seat" : "1-2",
"horizontal" : "0.21",
"vertical" : "0.22",
"status" : 2,
"transform" : "0deg",
"used" : 0,
"reserved" : 0,
"youReserved" : 0,
"empty" : 0
},
{
"carportId" : 3,
"seat" : "1-2",
"horizontal" : "0.21",
"vertical" : "0.22",
"status" : 2,
"transform" : "0deg",
"used" : 0,
"reserved" : 0,
"youReserved" : 0,
"empty" : 0
}
]


for( var i = 0; i< this. carportList4. length; i++) //整合两个数组数据,页面上遍历
{
var carstr = {
carportId: this. carportList4[ i]. id,
horizontal: this. carportList4[ i]. horizontal,
vertical: this. carportList4[ i]. vertical,
width: this. carportList4[ i]. width,
height: this. carportList4[ i]. height,
used: this. carportList3[ i]. used,
reserved: this. carportList3[ i]. reserved,
youReserved: this. carportList3[ i]. youReserved
};
this. carObj. push( carstr);
}


旋转div角度
for( var i = 0; i< this. carportList4. length; i++){
if( this. carportList4[ i]. transform != "0"){
// console.log(this.carportList4[i].transform);
var mydiv = document. getElementsByName( "carInfoDIv");
var mydiv2 = document. getElementById( mydiv[ i]. id);
mydiv2. style. transform = 'rotate(' + this. carportList4[ i]. transform+ 'deg)';
// console.log(mydiv2)
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王子様~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值