Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery动画不工作。可能语法不正确_Javascript_Jquery_Html - Fatal编程技术网

Javascript JQuery动画不工作。可能语法不正确

Javascript JQuery动画不工作。可能语法不正确,javascript,jquery,html,Javascript,Jquery,Html,我很不明白为什么这个基本的JQuery代码不起作用,我只想在点击按钮时将这个文本向右移动500px <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <met

我很不明白为什么这个基本的JQuery代码不起作用,我只想在点击按钮时将这个文本向右移动500px

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0   Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src = "jquery-2.0.1.js"></script>
<script>
$(document).ready(function(){
$('button').click(function(){
    $('div').animate({right:'500px'}, fast);
 });
});

</script>
</head>

<body>

<div style = "position: absolute; top: 100px;">
    Test Box
</div>
<button>click me</button>
</body>
</html>

无标题文件
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$('div').animate({右:'500px'},快速);
});
});
试验箱
点击我

单词
fast
需要加引号。或以毫秒为单位传入时间的
int

在部分:
$('div').animate({right:'500px'},fast)快速必须是:
“快速”


这对我有用

就在这里,代码的编写方式就像“fast”是一个变量:

     $('div').animate({right:'500px'}, fast);
“速度”参数应该用引号括起来,如下所示:

     $('div').animate({right:'500px'}, 'fast');
那就行了

$('div').animate({right:'500px'}, 'fast');
在这种情况下,效果应该是一个字符串,我们可以在数字也如下

$('div').animate({right:'500px'}, 500);

浏览器中的Javascript控制台是否显示任何错误?不,它只是在您尝试使用int值而不是
fast
时没有显示错误?请参阅OP在控制台中谎报错误,因为
fast
未定义。
$('div').animate({right:'500px'}, 500);