好办法,为响应棋盘游戏地图定做异型HTML元素 [英] Good way to map custom-shaped HTML elements responsively for a board game

查看:205
本文介绍了好办法,为响应棋盘游戏地图定做异型HTML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,我还没有想出如何响应调整的空间。我一直在使用大众/ VH的并%s的尝试,但都打破不同的看法大小的一致性。谁能推荐一个直接的方式来锁定这块板?

My problem is that I haven't figure out how to align the spaces responsively. I've tried using vw/vh's and %s but both break consistency on different view sizes. Can anyone recommend a straight-forward way to lock down this board?

我不想使用多个画布公元前50 +空格CPU漏,不希望使用影像地图,因为那是没有反应。

I didn't want to use multiple canvas bc of the cpu drain of 50+ spaces and don't want to use an image map because that's not responsive.

棋盘游戏

大家好和三角旗号,

我通过角1.x的努力端口棋盘游戏到HTML我有每个电路板空间的物体,并给予每个​​空间通过绝对定位(上左)位置的起源,并提出了快速的函数,它接受所有属性的转换属性,并返回CSS串在NG-风格转换

I'm trying to port a board game into HTML via angular 1.x. I have an object with each board space, and have given each space a location origin via absolute positioning (top, left) and made a quick function that takes all the properties in a transform property and returns a string for css transform in ng-style.

下面是第几个空格的例子:

Here's an example of the first few spaces:

1: {color: colors.blue, origin:{top:'65%', left:'13%'}, tForm: {rotate:'-21deg'}},
2: {color: colors.yellow, origin:{top:'66.5%', left:'8.5%'}, tForm: {rotate:'-35deg'}},
3: {color: colors.black, origin:{top:'70%', left:'6%'}, tForm: {rotate:'-72deg'}},
4: {color: colors.red, origin:{top:'75%', left:'5.5%'}, tForm: {rotate:'0deg'}},
5: {color: 'cool?', origin:{top:'80%', left:'6%'}, tForm: {rotate:'-21deg'}}

这里的code,它的处理这些属性(主要是在NG-风格):

Here's the code that's processing those properties (mostly in ng-style):

<span id="space-{{space}}" ng-repeat="space in section" ng-init="bgColor = cool.di.models.spaces[space].color === 'trap' ? '#900020' : cool.di.models.spaces[space].color === 'cool?' ? 'rgba(230,232,234, 1)': cool.di.models.spaces[space].color === 'pass' ? 'green' : cool.di.models.spaces[space].color" 
ng-style="{padding:'.1em', color:'mintcream', background:bgColor, border:'1px solid rgba(0,0,0,.2)', position:'absolute', top: cool.di.models.spaces[space].origin.top, left: cool.di.models.spaces[space].origin.left, transform: cool.di.api.tForm(cool.di.models.spaces[space].tForm), height:'2em', width:'2em'}">

下面是我对C https://irthos.github.io/cool目前的进展/#/板

感谢您的任何建议!

推荐答案

什么工作相当简单,使形状复杂的收集是一个重复的SVG元素与多边形子元素。

What worked fairly simply to make the complex collection of shapes was a repeated SVG element with polygon subelement.

该HTML:

<svg ng-style="{position:'absolute', background:'none', overflow: 'visible'}">
    <polygon points="{{points || '0,0 0,10 10,10 10,0 0,0'}}" stroke="black" fill="{{bgColor}}"></polygon>
 </svg>

在哪里点是正常化的观点尺寸从一个辅助函数生成的字符串:

Where points is a string generated from a helper function to normalize the view dimensions:

function(points){
    var pointsStr = '';
    points ?
    angular.forEach(points.split(' '), function (point) {
        var x = point.split(',')[0],
            y = point.split(',')[1];
        var hPx = Math.floor(($window.innerWidth / 100) * x),
            vPx = Math.floor(($window.innerHeight / 100) * y);
                pointsStr += hPx +','+vPx+' ';
            }) : null;
        return pointsStr.length > 0 ? pointsStr : null;
}

这解析'聚'属性字符串中的工厂对象:

Which parses the 'poly' property string in a factory object:

1: {color: colors.blue, poly:'13,5 8,5 10,11 12,11 13,5'},
2: {color: colors.yellow, poly:'8,5 4,8 7,13 10,11 8,5'},
3: {color: colors.black, poly:'4,8 1.8,13 5.5,16 7,13 4,8'},
4: {color: colors.red, poly:'1.8,13 0,19 5,19 5.5,16 1.8,13'},
5: {color: 'cool?', poly:'0,19 1,26 5.3,22.5 5,19 0,19'},
6: {color: colors.blue, poly: '1,26 3.5,31, 7,25 5.3,22.5 1,26'},
7: {color: colors.yellow, poly: '3.5,31 9,33 10,26 7,25 3.5,31'},
8: {color: colors.black, poly: '9,33 13,32 12,25.5 10,26 9,33'},
9: {color: 'cool?', poly:'13,32 18,28 15,24 12,25.5 13,32'}

全食宿渲染: https://irthos.github.io/cool/#/board

这篇关于好办法,为响应棋盘游戏地图定做异型HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆