【问题标题】:Trouble making animating boxes in jQuery在 jQuery 中制作动画框时遇到问题
【发布时间】:2015-03-08 03:44:47
【问题描述】:

我试图用 jQuery、CSS 和 HTML 制作 2 个动画框,但代码不起作用。我在一个 jQuery 教程应用程序中制作了该应用程序,它在该应用程序上运行良好。当我在我的电脑上使用确切的代码时,它不起作用。我的代码有什么问题?

这是我的代码:

    <!doctype html>
<html>
<head>
<title>Testing Stuff</title>
</head>
<body>
<div class="blueBox"></div>
<div class="redBox"></div>
<style>
.blueBox, .redBox {
    width: 100px;
    height: 100px;
    top: 20px;
    position: absolute;
}
.redBox {
    left: 20px;
    background-color: red;
}
.blueBox {
    left: 140px;
    background-color: blue; 
}
</style>
<script type="text/javascript">
$(document).ready(function(){
    var $blueBox = $('div.blueBox');
    var $redBox = $('div.redBox');
    $blueBox.animate({left: "500px"}, 2000, function(){alert("Animation Completed!");
    });
    $redBox.animate({width: "0px", height: "0px", opacity: "0"}, 3000);

});

</script>
</body>
</html>

谢谢你帮助我!!

【问题讨论】:

    标签: jquery html css animation jquery-animate


    【解决方案1】:

    您需要在 HTML 中链接 jQuery 代码:

    <script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>
    

    最好在标签中做。

    如果你想要above v1.11.1,通过jQuery download page直接从版本中获取代码链接。例如:

    <script src="http://code.jquery.com/jquery-2.1.3.min.js"
        type="text/javascript"></script>
    

    【讨论】:

    • 我必须将其链接到网页,还是可以将其链接到具有该代码的文档?
    • 您需要为每个使用它的 HTML 文档链接 jQuery 代码。
    • 尝试将变量名称从“$blueBox”和“$redBox”更改为“blueBox”和“redBox”。这在这里有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 2016-06-07
    • 2023-03-12
    相关资源
    最近更新 更多