jquery - 使用 margin-right 制作动画

标签 jquery css jquery-animate margin

简单的学习待办事项......但它对我不起作用。

任务很简单,我正在尝试旋转方形布局中的盒子(路径:向右 -> 向下 -> 向左 -> 向上)....但它没有动画当它向下移动后(不会向左向上移动),这是代码:

$('button').click(function () {
    $('.box').animate({
        "height": "40px",
            "width": "40px"
    }, 500, function () {
        $('.box').animate({
            "margin-left": "200px",  //go right
        }, 1500, function () {
            $('.box').animate({
                "margin-top": "200px", //go down
            }, 1500, function () {
                $('.box').animate({ // <===problem starts here
                    "margin-right": "200px" //go left
                    //"marginRight": "200px"
                }, 1500, function () {
                    $('.box').animate({
                        "margin-bottom": "200px" //go up
                    }, 1500, function () {
                        $('.box').css("background", "black")
                    });
                });
            });
        });
    });
});

在制作动画时是否有混合边距的正确方法?请指教...

Fiddle here

最佳答案

试试这个:

$('button').click(function () {
    $('.box').animate({
        "height": "40px",
            "width": "40px"
    }, 500, function () {
        $(this).animate({
            "margin-left": "200px",  //go right
        }, 1500, function () {
            $(this).animate({
                "margin-top": "200px", //go down
            }, 1500, function () {
                $(this).animate({ // <===problem starts here
                    "margin-left": "-=200px" //go left
                    //"marginRight": "200px"
                }, 1500, function () {
                    $(this).animate({
                        "margin-top": "-=200px" //go up
                    }, 1500, function () {
                        $(this).css("background", "black")
                    });
                });
            });
        });
    });
});

fiddle here

关于jquery - 使用 margin-right 制作动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26398398/

相关文章:

jquery animate或ease滚动左增量

javascript - jquery 切换动画/以相反的顺序

jquery - 强制 jQuery 动画使用整数值

javascript - 内部 js 工作正常,但外部没有

javascript - 比较数组变量

html - 如何创建透明框架集?

jquery - css 覆盖问题

html - 为什么div之间有空白?

Php/Jquery 表单和数据表

c# - 如何在 .NET 中从文本中去除 HTML?