猿问

请问这个能 for 出来吗?我手动写的代码,但是因为脑子不够用,不会简化了...

这个是个 3 * 3 的图片排版;
以后可能要做 100*100 的图片排版....

我想定义俩变量,一个 row , 一个Column,然后自动 for 出来 ,
因为我这个脑子不怎么够用,所以请大家帮帮了..

这是 x , 由 border 和 width 组成的 , 简称 b 和 w...
y 也同理...

上面的已经简化了:

https://img.mukewang.com/5be0f9ef00011fff02720173.jpg

这是图片左上角的坐标

https://img2.mukewang.com/5be0f9fb0001d7e702860263.jpg

这是按照顺时针的四个点...

https://img.mukewang.com/5be0fa0b0001320806600248.jpg

https://img1.mukewang.com/5be0fa1600012c7705170522.jpg

慕的地8271018
浏览 596回答 1
1回答

万千封印

我用js写了var border = 10;var width = 30;var height = 40;// 生成指定位置数据function genPosition (row, col) {&nbsp; &nbsp; var fullWidth = border * 2 + width;&nbsp; &nbsp; var fullHeight= border * 2 + height;&nbsp; &nbsp; return {&nbsp; &nbsp; &nbsp; &nbsp; point1: {x: col * fullWidth + border, y: row * fullHeight + border},&nbsp; &nbsp; &nbsp; &nbsp; point2: {x: col * fullWidth + border + width, y: row * fullWidth + border},&nbsp; &nbsp; &nbsp; &nbsp; point3: {x: col * fullWidth + border + width, y: row * fullWidth + height + border},&nbsp; &nbsp; &nbsp; &nbsp; point4: {x: col * fullWidth + border, y: row * fullHeight + height + border}&nbsp; &nbsp; };}for (var i = 0; i < 3; i++) {&nbsp; &nbsp; for (var j = 0; j < 3; j++) {&nbsp; &nbsp; &nbsp; &nbsp; var pos = genPosition(i, j);&nbsp; &nbsp; &nbsp; &nbsp; // 随便用pos&nbsp; &nbsp; }}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答