javascript - How to slide/grow a tile to position with 90x90px with CSS -
i want make grid[row1][col1] slide grid[row2][col2] make grow 90x90px
any ideas how this?
style :
<style type="text/css"> #grid { background-color: #ccc0b3; width: 400px; height: 400px; position: relative; border-radius: 5px; } .box { width: 80px; height: 80px; border-radius: 5px; font-family: arial, sans-serif; font-size: 35px; font-weight: bold; display: inline-block; position: absolute; padding: 5px; margin: 5px; text-align: center; line-height: 80px; } </style>
javascript : creating class named box
function makenew(row, col) { var number = math.random() < 0.9 ? 2 : 4; var color = pikcolor(number); var textcolor = textcolor(number); return grid[row][col] = $('<div>') .css({ background: color, color: "blue", top : row * 100 + 'px', left : col * 100 + 'px' }) .text(number) .addclass('box') .appendto($('#grid')); }
updating grid[row2][col2] grid[row1][col1]:
function merge(row1, col1, row2, col2) { if (merging[row2][col2]) { return false; } grid[row2][col2].remove(); grid[row2][col2] = grid[row1][col1]; grid[row1][col1] = null; var number = grid[row2][col2].text() * 2 ; var color = pikcolor(number); var textcolor = textcolor(number); alert(number); alert(textcolor); merging[row2][col2] = true; grid[row2][col2] .css({ background: color, color: textcolor, top : row2 * 100 + 'px', left : col2 * 100 + 'px' }) .text(number); return true; }
thanks
i use jquery .animate function, this:
grid[row1][col1].animate({ top: row2 * 100, left: col2 * 100, width: 90, height: 90 }, { duration: 1000 })
Comments
Post a Comment