Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- python
- 교보
- 프로그래밍
- 교보생명
- 가입
- Java
- 웹개발
- 중도인출
- 변환
- 추가납입
- 심장질환
- javascript
- 사망
- 코딩
- 수수료
- 문자열
- Vue.js
- 자바스크립트
- 인출수수료
- jQuery
- 특약
- 프론트엔드
- PythonProgramming
- 보험료
- 급성심근경색증
- 뇌출혈
- 파이썬
- 납입
- 보험
- 리스트
Archives
- Today
- Total
SeouliteLab
jQuery .mousemove() 메서드: 마우스 이동 감지하기 본문
예제 1: 마우스 위치 표시하기
<!DOCTYPE html>
<html>
<head>
<title>jQuery .mousemove() 메서드 예제</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$(document).mousemove(function(event){
$("#coordinates").text("X: " + event.pageX + ", Y: " + event.pageY);
});
});
</script>
</head>
<body>
<div id="coordinates"></div>
</body>
</html>
설명: 이 예제는 마우스 이동 시 마우스의 X 및 Y 좌표를 실시간으로 표시합니다.
예제 2: 마우스 이동에 따른 요소 스타일 변경하기
<!DOCTYPE html>
<html>
<head>
<title>jQuery .mousemove() 메서드 예제</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$(document).mousemove(function(event){
var color = "rgb(" + event.pageX + ", " + event.pageY + ", 100)";
$("body").css("background-color", color);
});
});
</script>
</head>
<body>
<p>마우스를 이동하세요.</p>
</body>
</html>
설명: 이 예제에서는 마우스의 X 및 Y 좌표를 사용하여 body의 배경색을 동적으로 변경합니다.
예제 3: 마우스 이동 시 이펙트 적용하기
<!DOCTYPE html>
<html>
<head>
<title>jQuery .mousemove() 메서드 예제</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$(document).mousemove(function(event){
$("#box").stop().animate({
left: event.pageX,
top: event.pageY
}, 100);
});
});
</script>
<style>
#box { position: absolute; width: 50px; height: 50px; background-color: red; }
</style>
</head>
<body>
<div id="box"></div>
</body>
</html>
설명: 이 예제에서는 마우스가 이동할 때마다 상자를 따라 움직이는 이펙트를 적용합니다.
예제 4: 마우스 이동에 따른 툴팁 표시하기
<!DOCTYPE html>
<html>
<head>
<title>jQuery .mousemove() 메서드 예제</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$(document).mousemove(function(event){
$("#tooltip").css({
top: event.pageY + 10,
left: event.pageX + 10
});
});
});
</script>
<style>
#tooltip { position: absolute; background-color: #fff; border: 1px solid #000; padding: 5px; }
</style>
</head>
<body>
<div id="tooltip">마우스 위치를 표시하는 툴팁입니다.</div>
</body>
</html>
설명: 이 예제에서는 마우스의 위치에 따라 동적으로 툴팁을 표시합니다.
예제 5: 이미지 확대/축소하기
<!DOCTYPE html>
<html>
<head>
<title>jQuery .mousemove() 메서드 예제</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$(document).mousemove(function(event){
var scale = event.pageX / $(window).width();
$("#image").css("transform", "scale(" + scale + ")");
});
});
</script>
<style>
#image { width: 200px; height: auto; transition: transform 0.1s ease; }
</style>
</head>
<body>
<img src="example.jpg" id="image">
</body>
</html>
설명: 이 예제에서는
마우스의 X 좌표에 따라 이미지의 크기를 동적으로 조절하여 확대 또는 축소합니다.