JQuery动画功能不起作用

Jon*_*ony -4 jquery

animate在jQuery中的函数有问题.我在本地工作,该函数不会动画我的div元素.

<!DOCTYPE html>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script>
            $(document).ready(function() {
                $("button").click(function() {
                    $("div").animate({left: '250px'});
                });

            });
        </script>       
    </head>
    <body>

        <div style="position:absolute"> Animate Box </div>
        <button> Start </button>

    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

ade*_*neo 5

动画工作得很好,但元素没有移动,因为它没有位置或起点:

<!DOCTYPE html>
<html>
    <head>
        <style type="text/css">
            div {position: relative; left:0;}
        </style>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script>
            $(document).ready(function() {
                $("button").click(function() {
                    $("div").animate({left: '250px'});
                });
            });
        </script>       
    </head>
    <body>
        <div> Animate Box </div>
        <button> Start </button>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

小提琴

  • @Jasper - 它现在已经没有了我复制代码的时候 (3认同)