-
카테고리
-
세부 분야
웹 개발
-
해결 여부
해결됨
wall3d.js에서 마우스위치 x,y 값이 안잡히는데 이유를 알수 있을까요? {x: NaN, y: NaN}
20.10.23 17:33 작성 조회수 252
0
(function() {
const stageElem = document.querySelector('.stage');
const houseElem = document.querySelector('.house');
const barElem = document.querySelector('.progress-bar');
const mousePos = {x:0, y:0};
let maxScrollValue;
function resizeHandler(){
maxScrollValue = document.body.offsetHeight - window.innerHeight;
}
window.addEventListener('scroll', function(){
const scrollPer = pageYOffset / maxScrollValue;
const zMove = scrollPer * 980 - 490;
houseElem.style.transform = `translateZ(${zMove}vw)`;
barElem.style.width = scrollPer * 100 + '%';
});
window.addEventListener('mousemove', function(e){
mousePos.x = -1 + (e.ClientX / window.innerWidth) * 2;
mousePos.y = 1 - (e.ClientY / window.innerHeight) * 2;
console.log(mousePos);
});
window.addEventListener('resize', resizeHandler);
resizeHandler();
})();
답변을 작성해보세요.
0
0
0
답변 3