简体   繁体   English

将div元素滑动到另一个元素JQuery

[英]Slide div element to another element JQuery

I have an Array grid Contains some 我有一个数组网格包含一些 . this how how I create 这是我如何创造

grid[row][col] = $('<div>')
        .css({
          top  : row * 100 + 'px',
          left : col * 100 + 'px'
        })
        .text(number)
        .addClass('box')
        .appendTo($('#grid'));

This function merge where I move one div to another. 此功能合并到哪里我将一个div移动到另一个。 but i want to make an animation to slide the grid[row1][col1] div to grid[row2][col2] div. 但我想制作一个动画,将grid [row1] [col1] div滑动到grid [row2] [col2] div。

function merge(row1, col1, row2, col2) {
    grid[row2][col2].remove();
    grid[row2][col2] = grid[row1][col1];
    grid[row1][col1] = null;
    var number = grid[row2][col2].text() * 2 ;


    grid[row2][col2]
       .css({
           top  : row2 * 100 + 'px',
           left : col2 * 100 + 'px'
        })
        .text(number);

    return true;
}

Any Idea please how to Do this. 任何想法请怎么做。

Instead of css() you can try animate() : 可以使用animate()代替css() animate()

grid[row2][col2].text(number);
grid[row2][col2].animate({
    top  : row2 * 100 + 'px',
    left : col2 * 100 + 'px'
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM