开发者

How to move a div to a predefined path using the keyboard, AJAX & jQuery

开发者 https://www.devze.com 2023-03-16 23:11 出处:网络
Hello is there any way to use the keyboard lets say the Enter button and move a div to a path that I defined earlier ? With path I mean for example to move some steps right, then down, then left and s

Hello is there any way to use the keyboard lets say the Enter button and move a div to a path that I defined earlier ? With path I mean for example to move some steps right, then down, then left and so on. The main goal is to use a path either amanual with keypress or with a body o开发者_Python百科nload command. Any help/idea/example is appeciated..


You can use jQuery's animate() on the div in response to keypress events.

$(document).keypress(function(e) {
    var anim_params;
    if (div in state 1) {
        anim_params = state 2 params;
    } else  if (div in state 2) {
        anim_params = state 3 params;
    } else if (...) {
        ...
    }

    $('#div_id').animate(anim_params);
});

Of course you can replace those if statements with a lookup, but you get the idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消