2
我有一個圓形的div,跟着你的鼠標使用Javascript,但我希望它停止時,它擊中了容器div的邊緣。我會怎麼做?這裏是JavaScript的即時通訊使用:我該如何使用jQuery跟隨帶有div的光標?
var mouseX = 0, mouseY = 0;
$(document).mousemove(function(e){
mouseX = e.pageX;
mouseY = e.pageY;
});
// cache the selector
var follower = $("#follower");
var xp = 0, yp = 0;
var loop = setInterval(function(){
// change 12 to alter damping higher is slower
xp += (mouseX - xp)/12;
yp += (mouseY - yp)/12;
follower.css({left:xp, top:yp});
}, 30);
,這裏是一切我到目前爲止有:jsFiddle
請幫忙,謝謝!