如何使用鼠标位置创建移动元素,如http://fieroanimals.com/?

Ale*_*ets 4 html mouse jquery position image

我想用里面的图像创建div元素,并用鼠标位置的坐标改变它的位置.有一些用于创建3D效果的jquery-pluings,但我只需要在X和Y坐标上移动.另外,在div元素的限制中这样做.

我有下一个代码:

$('div.images').mousemove(function(e){
        var x = e.pageX - this.offsetLeft;
        var y = e.pageY - this.offsetTop;
        $('div.images').css({'top': x,'left': y}); 
    });
Run Code Online (Sandbox Code Playgroud)

在CSS div.images有绝对的位置.当我移动鼠标时不改变位置,但是当我删除CSS中的位置时,它会对元素的样式应用更改,但不会更改位置.

给我一些建议我需要做什么.

http://fieroanimals.com/上实现了Flash,但我想在JQuery上做到这一点.

Use*_*r99 6

我知道这是一个老问题.但这个答案对新用户来说是可行的.答案100%有效.

$(document).ready(function(){
      $('div.moveAble-container').mousemove(function(e){
            var y = e.pageY;
            var x = e.pageX;                    
            $('div.moveAble').css({'top': y}); 
            $('div.moveAble').css({'left': x});

      });
    });
Run Code Online (Sandbox Code Playgroud)