http://laboratory.stratusweb.co.uk/lea/ (아직 완료되지 않음)살아 움직이는듯한 눈 - 왜 스크롤 할 때 따라 오는가?
눈이 커서를 따라갑니다.
내가 알아낼 수없는 것은 스크롤 할 때 눈이 페이지 아래로 이동하는 이유입니다.
모든 의견 환영합니다! 스크롤하는 동안
var windowX = -1;
var windowY = -1;
jQuery(document).ready(function() {
var canvas = document.getElementById("debugCanvas");
canvas.width = document.width;
canvas.height = document.height;
jQuery(document).mousemove(function(e) {
var mousePosition = {
'x' : e.pageX,
'y' : e.pageY
};
var context = document.getElementById("debugCanvas").getContext("2d");
jQuery(".eyeContainer").each(function(i, i2) {
var eyeContainerPosition = $(this).offset();
var eyePosition = {
'x' : eyeContainerPosition.left + $(this).width()/2 +1,
'y' : eyeContainerPosition.top - $('body').scrollTop() + $(this).height()/2 +1
}
var slope = getSlope(eyePosition, mousePosition);
var toCenterdistance = getDistance(eyePosition, mousePosition);
var targetDistance = toCenterdistance - ($(this).width()/2);
if(toCenterdistance > ($(this).width()/2)) {
var x = Math.cos(Math.atan(slope)) * targetDistance;
if(eyePosition.x > mousePosition.x) {
x += mousePosition.x;
} else if(eyePosition.x < mousePosition.x) {
x = -x + mousePosition.x;
}
var y = Math.sin(Math.atan(slope)) * targetDistance;
if(eyePosition.x > mousePosition.x) {
y += mousePosition.y;
} else if(eyePosition.x < mousePosition.x) {
y = -y + mousePosition.y;
}
x -= $(this).height()/2;
y -= $(this).height()/2;
} else {
x = mousePosition.x - ($(this).width()/2);
y = mousePosition.y - ($(this).width()/2);
}
var element=$("#eyeBall_" + $(this).attr("rel"));
element.css({
'left' : x + 'px',
'top' : y + 'px',
});
});
})
});
function getSlope(loc1, loc2) {
return (loc1.y - loc2.y)/(loc1.x - loc2.x);
}
function getDistance(loc1, loc2) {
return Math.sqrt(Math.pow((loc1.x - loc2.x), 2) + Math.pow((loc1.y - loc2.y), 2));
}
omg, 무서운 것 같습니다 :) – galymzhan
눈을 움직이는 코드를 복사/붙여 넣기해야 할 수도 있습니다. 문제가있을 수 있습니다. –
관련 코드를 게시하여이 질문을 "자체 포함"하십시오. 전체 사이트의 코드를 파기하는 것이 비실용적 일뿐만 아니라 미래의 독자는 문제가 해결 된 후 이로부터 혜택을 볼 수 없습니다. http://meta.stackexchange.com/a/129787을 참조하십시오. – Sparky