index-m.html 2.73 KB
<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>