<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div class="special"></div>
<div></div>
<div></div>
<script>
const special = document.querySelector('.special'); //변수를 선언한다
special.addEventListener('click', (event) => { //클릭시 이벤트를 나타내고
const rect = special.getBoundingClientRect(); //이벤트에서 받는 값을 변수로 선언한다.
console.log(rect); 받아오는 모든 값을 나타낸다.
console.log(`client: ${event.clientX}, ${event.clientY}`);
//받아온 값에서 내가보는 화면 기준의 x,y 좌표값을 출력한다.
console.log(`page: ${event.pageX}, ${event.pageY}`);
//받아온 값에서 전체 화면 기준의 x,y 좌표값을 출력한다.
})
</script>
</body>
(기초) 제어문 (0) | 2023.01.05 |
---|---|
(기초) 연산자 (0) | 2023.01.04 |
(기초) 변수 타입 (0) | 2023.01.04 |
윈도우 사이즈 구하기 (0) | 2022.11.28 |