好吧所以我只需要在我正在建立的网站上学习几个动画的JQuery。
我一直在阅读JQuery网站上的教程,我只想尝试实现一个简单的对角移动动画。
我仍然是JQuery的新手(如今,从今天开始),但从我理解的一切,下面的代码应该工作。 我犯了什么错误?
$(document).ready(function(){ $("#moveme").click(function(event){ $("#moveme").animate({right: '+=50', bottom: '+=50'}, 1000); }); }); Move this text
编辑:
添加了来自css和固定括号问题的相对属性与document
但仍然无法正常工作。
您似乎忘记了一些括号来正确选择元素。
那个怎么样?
$(document).ready(function(){ $("#moveme").click(function(event){ $(this).animate({right: '+=50', bottom: '+=50'}, 1000); }); });
编辑:
另外,请确保您要导入jQuery脚本库 :
你错过了$(文件)
$的document.ready(函数(){
你的jquery动画函数也正在改变你的id =“moveme”的CSS
我确保在你的CSS中你有这个。
#id { position: relative; }
你绝对可以这样做:
$(document).ready(function(){ $("#moveme").click(function(event){ $(this).animate({'margin-left': '+=50', 'margin-top': '+=50'}, 1000); }); });
在这里工作演示(只需点击div’hello’): http : //jsfiddle.net/px2jz/
以上就是jQuery教程分享无法使元素与jQuery animate()对角移动相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/jquerytutorial/547729.html