js:图片随鼠标移动的方法 鼠标移动
程序员文章站
2022-05-29 20:04:56
...
仅写出我知道的两种方法
方法一:
$(document).mousemove(function(e){
$("span").text(e.clientX + ", " + e.clientY);
var x =e.clientX;
var y = e.clientY;
document.getElementById("img").style.left=x+"px";
document.getElementById("img").style.top=y+"px";
});
方法二:
$(document).mousemove(function(e){
$("span").text(e.clientX + ", " + e.clientY);
var x =e.clientX;
var y = e.clientY;
$("#img").animate({"left":x,"top":y},1);
});
方法一:
$(document).mousemove(function(e){
$("span").text(e.clientX + ", " + e.clientY);
var x =e.clientX;
var y = e.clientY;
document.getElementById("img").style.left=x+"px";
document.getElementById("img").style.top=y+"px";
});
方法二:
$(document).mousemove(function(e){
$("span").text(e.clientX + ", " + e.clientY);
var x =e.clientX;
var y = e.clientY;
$("#img").animate({"left":x,"top":y},1);
});