我是 jquery 的新手。但这似乎不起作用。我正在尝试制作动画,并且我已经从字面上复制并粘贴了一个代码到记事本中,并像您一样将其保存为 xxx.html。我从哪里得到它的是这里的 jquery 站点 - https://api.jqueryui.com/bounce-effect/
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bounce demo</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<style>
#toggle {
width: 100px;
height: 100px;
background: #ccc;
}
</style>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<p>Click anywhere to toggle the box.</p>
<div id="toggle"></div>
<script>
$( document ).click(function() {
$( "#toggle" ).toggle( "bounce", { times: 3 }, "slow" );
});
</script>
</body>
</html>
它在网站上运行完美,但当我在 Google chrome 或 opera 上运行它时,它就是不起作用。它没有动画。我不确定为什么。有人可以帮忙吗?谢谢。
最佳答案
您可能是通过打开文件而不是通过网络服务器在计算机上本地运行该示例。
该示例使用 //
加载 jQuery 文件,这意味着它遵循您在浏览器栏中使用的协议(protocol)。例如 http://
或 https://
。
但是因为您通过 file://
在本地打开它,所以它会尝试通过 file://
加载其他文件。您本地没有其他文件。
修复它的最简单方法是手动更新 jQuery 路径并添加一个协议(protocol):
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
另一种不更改代码的修复方法是通过网络服务器运行文件并通过 https://xxxxx.xxx
或 http://xxxxx.xxx 请求它
关于javascript - 我的 jquery 代码没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39196363/