答案 0 :(得分:0)
一种方法是迭代相对点并标准化唯一视图的宽度和高度像素。
var originalPointsString = '0,0 0,1 1,1 1,0 0,0'; //points to a square
var newPointsStr = '';
forEach(originalPointsString.split(' '), function(point){
var x = point.split(',')[0], // gets the x coord from each point
y = point.split(',')[1]; // gets the y coord from each point
var hPx = Math.floor((window.innerWidth / 100) * x), // gets how many pixels per percent in a given view's width
vPx = Math.floor((window.innerHeight / 100) * y); // gets how many pixels per percent in a given view's height
newPointsStr += hPx +','+vPx+' '; // build new point coords based on the normalized view percents
})
// Given example 1000px x 500px view
// newPointsStr === '0,0 0,5 10,5 10,0 0,0'
这将对负载做出响应,但您必须使用其他魔法来监视窗口调整大小。