1

这是我的 HTML 页面:

<!DOCTYPE html>
<html lang="en">

    <head>

        <title>Example</title>

        <meta charset="utf-8">

        <link rel="stylesheet" type="text/css" href="content/main.css">

        <script src="content/jquery.js" type="text/javascript"></script>
        <script type="text/javascript">
        $("#container").animate({
            'background-position': '1110px 1110px'
        }, 1000, function () {
        });
        </script>

    </head>

    <body>

        <div id="container">

            <p>hello</p>

        </div>

    </body>

</html>

容器应该使用该divJavaScript 代码进行动画处理,但在打开页面时没有任何反应。我在这里做错了什么?

4

1 回答 1

1

您的代码在DOM 树完全构建之前运行。所以你需要用

$(function() { // <--- begin of the wrap

        $("#container").animate({
            'background-position': '1110px 1110px'
        }, 1000, function () {
        });

}); // <---- end of the wrap

http://api.jquery.com/ready/

于 2012-05-18T03:39:19.090 回答