如何在jQuery对角运动中移动元素? [英] How to move an element in Diagonal Movement in jQuery?
本文介绍了如何在jQuery对角运动中移动元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何在jQuery中上下移动元素.
I know how to move up and down an element in jQuery.
$("#div").animate({"left": "+=100"}, 1000); //move 100px to the right
但是我不知道要以对角线移动.我正在做棋盘,但我不知道如何有效地移动Bishop.请查看以下URL http://chess.diem-project.org/
But I have no idea to move in diagonal movement. I'm doing chess board and I don't know how to move Bishop with effect. Please have a look at following URL http://chess.diem-project.org/
我确实喜欢这样...但这不是正确的方法.
I did like this... but it's not a proper way.
for(var i = 0;i<50;i++){ // move down and move right 1 pixel at a time to get effect
$("#div").animate({"left": "+="+x}, 1);
$("#div").animate({"top": "+="+x}, 1);
}
有什么主意吗?非常感谢您的帮助!
Any idea? Really appreciate your helps!
推荐答案
这样做:
$("#div").animate({left: '+=50', top: '+=50'}, 1000);
您想让一个动画到达那里...一个for循环将100个动画排队,您只需要一个:)
You want one animation to get you there...a for loop queues 100 animations in your case, you just need the one :) See a demo here
这篇关于如何在jQuery对角运动中移动元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文