我想创建一个内部有图像的 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});
});
在 CSS 中,div.images 具有绝对位置。当我移动我的鼠标时,我的位置没有改变,但是当我在 CSS 中删除位置时,它应用了对元素样式的更改,但没有改变位置。
给我一些建议,我需要做什么。
在 http://fieroanimals.com/这是在 Flash 上实现的,但我想在 JQuery 上实现。
最佳答案
$(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});
});
});
关于jquery - 如何使用鼠标位置创建移动元素,例如 http ://fieroanimals. com/?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11244309/