我已经设置了这个jsfiddle:http://jsfiddle.net/386er/dhzq6q6f/14/
var moveCell = function(direction) {
var cellToBeMoved = pickRandomCell();
var currentX = cellToBeMoved.x.baseVal.value;
var currentY = cellToBeMoved.y.baseVal.value;
var change = getPlusOrMinus() * (cellSize + 1 );
var newX = currentX + change;
var newY = currentY + change;
var selectedCell = d3.select(cellToBeMoved);
if (direction === 'x') {
selectedCell.transition().duration(1500)
.attr('x', newX );
} else {
selectedCell.transition().duration(1500)
.attr('y', newY );
}
Run Code Online (Sandbox Code Playgroud)
}
在moveCell函数中,我选择一个随机单元格,请求其当前的x和y坐标,然后添加或减去其宽度或高度,以将其移动到相邻的单元格.
我想知道的是:如果你观察细胞移动,有些只会部分移动到下一个细胞.anoyne可以告诉我,为什么会这样?