无法使元素与jQuery animate()对角移动 [英] Unable to make an element move diagonally with jQuery animate()

查看:333
本文介绍了无法使元素与jQuery animate()对角移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我只需要在我建立的网站上学习一些动画的JQuery。



我一直在阅读JQuery网站上的教程,只是试图实现一个简单的对角线移动动画。



我还是非常新的JQuery(如今,从今天开始),但从我了解的一切,以下代码应该工作。我在做什么错误?

 < head> 
< script type =text / javascriptsrc =JQuery.js>
< / script>

< script>
$(document).ready(function(){
$(#moveme)。click(function(event){
$(#moveme)。animate :'+ = 50',bottom:'+ = 50'},1000);
});
});
< / script>
< / head>

< body>
< div id =moveme>
移动此文本
< / div>
< / body>

编辑:



从css添加相对属性,使用文档添加固定括号问题,但仍然无法使用。

解决方案

您似乎忘记了一些括号,以正确选择元素。



该怎么办?



($($)$($)$($)$($)$($) ).animate({right:'+ = 50',bottom:'+ = 50'},1000);
});
});

编辑:



另外,请确保您正在导入jQuery脚本库:

 < script SRC = http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js >< /脚本> 


Alright so I only need to learn JQuery for a couple of animations on a site I'm building.

I've been reading the tutorials on the JQuery site and am just trying to implement a simple diagonal move animation.

I'm still extremely new to JQuery (as in, started today) but from everything i understand, the following code should work. What error am i making?

<head>
<script type="text/javascript" src="JQuery.js">
</script>

<script>
$(document).ready(function(){
    $("#moveme").click(function(event){
    $("#moveme").animate({right: '+=50', bottom: '+=50'}, 1000);​​​​​​​​​​​​​​​ 
    });
});
</script>
</head>

<body>
<div id="moveme">
Move this text
</div>
</body>

Edit:

Added relative property from css and fixed parenthesis issue with document but still not working.

解决方案

It seems that you forgot some parenthesis to select the elements correctly.

What about that?

$(document).ready(function(){
    $("#moveme").click(function(event){
        $(this).animate({right: '+=50', bottom: '+=50'}, 1000);​​​​​​​​​​​​​​​ 
    });
});

Edit:

Also, make sure that you are importing the jQuery script library:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

这篇关于无法使元素与jQuery animate()对角移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆