index-m.html
2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<script type="text/javascript" src="./jquery.js"></script>
<style>
.xnPosition{
position: relative;
width: 100%;
padding-top: 100%;
background: red;
overflow: hidden;
}
.xnPosition .item-logistic{
position: absolute;
left: 0;
top:0;
font-size: 12px;
width: 10%;
height: 10%;
background: green;
overflow: hidden;
text-align: center;
background: url("./item-logistic.png") center 50% no-repeat;
background-size: 100% 100%;
color: #fff;
}
</style>
</head>
<body >
<!--设置-->
<div id="position" class="xnPosition">
</div>
</body>
<script type="text/javascript">
function drawLogistic (id) {
var $drawId=$("#position");
var drawWidth=$drawId.width();
function setScale(worth) {
var scale= drawWidth/640;
return scale*worth;
}
$.ajax({
contentType: "application/json",
type: "post",
url: "data.json",
dataType: "json"
}).success(function (data) {
var dome="";
var itemList=data.items;
for(var i=0; i<itemList.length;i++){
var item={
id:itemList[i].id,
value:itemList[i].value,
offsetX:setScale(itemList[i].offsetX),
offsetY:setScale(itemList[i].offsetY),
width:setScale(itemList[i].width),
height:setScale(itemList[i].height),
rotate:itemList[i].rotate||0,
zIndex:i,
};
dome+="<div class=\"item-logistic\" data-id=\""+item.id+"\" " +
"style=\"left:"+item.offsetX+"px;" +
"top:"+item.offsetY+"px;" +
"width:"+item.width+"px;" +
"height:"+item.height+"px;" +
"line-height:"+item.height+"px;" +
"transform:rotate("+item.rotate+"deg);" +
"z-index:"+item.zIndex+"" +
"\">"+item.value+"</div>"
}
$drawId.css({background:"url("+data.pictureUrl+") center 50% no-repeat", "background-size":"100% 100%"});
$drawId.html(dome);
})
}
drawLogistic("#position");
</script>
</html>