【问题标题】:How to move an element in Diagonal Movement in jQuery?如何在jQuery的对角线移动中移动元素?
【发布时间】:2013-03-25 07:19:22
【问题描述】:

我知道如何在 jQuery 中上下移动元素。

$("#div").animate({"left": "+=100"}, 1000); //move 100px to the right

但我不知道沿对角线移动。我正在下棋盘,我不知道如何有效地移动 Bishop。请查看以下网址http://chess.diem-project.org/

我确实喜欢这个……但这不是正确的方法。

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); 
} 

有什么想法吗?非常感谢您的帮助!

【问题讨论】:

    标签: jquery jquery-ui


    【解决方案1】:

    这样做:

     $("#div").animate({left: '+=50', top: '+=50'}, 1000);
    

    你想要一个动画让你到达那里......在你的情况下,一个 for 循环队列 100 个动画,你只需要一个 :) See a demo here

    【讨论】:

    • 正是我需要的。惊人的答案!非常感谢尼克!
    猜你喜欢
    • 2012-10-22
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2021-06-21
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多