• 회원가입
  • 로그인
  • 구글아이디로 로그인

[Event] JQ - mouseenter() 메서드 ★★★ - mouseenter 이벤트발생/함수실행. (= mouseenter메서드 = 마우스엔터 메서드)

목차

  1. mouseenter() 예제 - mouseenter 이벤트 때 경고창 띄우기
  2. mouseenter() 정의
  3. mouseenter() 구문
  4. mouseenter() 예제 - cf. mouseover(), mousemove()

 

mouseenter() 예제 - mouseenter 이벤트 때 경고창 띄우기

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<script>

$(document).ready(function(){

    $("#hz").mouseenter(function(){

        alert("Homzzang.com");

    });

});

</script>


<p id="hz">홈짱닷컴 주소 보기</p>


결과보기

 

mouseenter() 정의

 

mouseenter 이벤트는 마우스커서가 선택 요소로 들어갈 때 발생.

※ mouseenter() 메서드는 2가지 작동 가능.

① mouseenter 이벤트 촉발.

② mouseenter 이벤트 발생 시 실행할 함수 연결.

 


 

1. 함수 비교.

 

mouseover() 메서드

: 마우스커서가 선택 요소 및 자식 요소에 들어가면 이벤트 발생.

 

mouseenter() 메서드

: 마우스커서가 선택 요소에 들어갈 때만 이벤트 발생.

 

2.

mouseleave() 메서드와 주로 함께 사용됨.

 

 

mouseenter() 구문

 

mouseenter 이벤트 촉발.

$(selector).mouseenter()

 

mouseenter 이벤트에 함수 연결.

$(selector).mouseenter(function)

 


[매개변수]

 

function

선택. mouseenter 이벤트 발생 시 실행할 함수 지정.

 

 

mouseenter() 예제 - cf. mouseover(), mousemove()

 

<style>

div {

  width: 200px;

  height: 100px;

  border: 1px solid black;

  margin: 10px;

  float: left;

  padding: 30px;

  text-align: center;

  background-color: lightgray;

}

h3 {background-color: white; padding:20px;}

span {display;block; color:red;}

</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

var x = 0;

var y = 0;

var z = 0;

$(document).ready(function(){

  $("div.over").mouseover(function(){

    $(".over span").text(x += 1);

  });

  $("div.enter").mouseenter(function(){

    $(".enter span").text(y += 1);

  });

  $("div.move").mousemove(function(){

    $(".move span").text(z += 1);

  });

});

</script>



<div class="over">

  <h3>Mouseover 횟수: <span></span></h3>

</div>


<div class="enter">

  <h3>Mouseenter 횟수: <span></span></h3>

</div>


<div class="move">

  <h3>Mousemove 횟수: <span></span></h3>

</div>

 

결과보기


PS.

 

mouseover 이벤트

: 마우스커서가 div, h3 각각 들어갈 때 이벤트 발생.

 

mouseenter 이벤트

: 마우스커서가 div 들어갈 때만 이벤트 발생.

 

mousemove 이벤트

: 마우스커서가 div 위에서 1px 움직일 때마다 이벤트 발생.

 


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
Event JQ - event ★ - 이벤트 (= 메서드실행 촉발사건) ※ e 매개변수를 명시적으로 전달해야 하는 이유
Event JQ - $(document).ready() 메서드 ★ - 문서로드완료후 실행 (= ready메서드 = 다…
Event JQ - click() 메서드 ★ - click 이벤트발생/함수실행. (= click메서드 = 클릭 메서드…
Event JQ - dblclick() 메서드 ★ - dblclick 이벤트발생/함수실행. (= dblclick메서드 …
Event JQ - mouseenter() 메서드 ★★★ - mouseenter 이벤트발생/함수실행. (= mousee…
Event JQ - mouseleave() 메서드 ★ - mouseleave 이벤트발생/함수실행 (= mouseleav…
Event JQ - mousedown() 메서드 - mousedown 이벤트발생/함수실행. (= mousedown메서…
Event JQ - mouseup() 메서드 - mouseup 이벤트발생/함수실행. (= mouseup메서드 = 마우스…
Event JQ - hover() 메서드 ★ - hover 이벤트발생/함수실행. (= hover메서드 = 허버 메서드)
Event JQ - blur() 메서드 ★ - 포커스 해제/제거(= blur메서드 = 블러메서드) ※ 포커스 시 아웃…
Event JQ - on() 메서드 ★★★★★ - 이벤트핸들러 부착 (= 여러이벤트・여러메서드 함께실행 = 이벤트부착…
Event JQ - bind() 메서드 - JQ 3.0 폐기예고. / 요소에 이벤트 부착. (= bind메서드 = 바인…
Event JQ - change() 메서드 ★★★ - 입력값 변동/변화 시 이벤트 발생. (= change메서드 = …
Event JQ - delegate() 메서드 - JQ 3.0 폐기예고. / 하위요소(자식요소)에 이벤트핸들러 부착. …
Event JQ - die() 메서드 - JQ 1.7 폐기예고, JQ 1.9 폐기완료. / 이벤트 제거. (= die메…
Event JQ - error() 메서드 - JQ 1.8 폐기예고. JQ 3.0 폐기완료. / 에러 이벤트 촉발 + 에…
Event JQ - event.currentTarget 속성 - 현재 이벤트 요소 반환. (= 이벤트.커런트타겟 속성)
Event JQ - event.data 속성 - 이벤트 메서드에 전달된 값을 반환. (=이벤트.데이터 속성) ※ 데이터…
Event JQ - event.delegateTarget 속성 ★ - 현재 호출된 이벤트 핸들러가 부착된 요소 반환. …
Event JQ - event.isDefaultPrevented() 메서드 - event.preventDefault()…
1/3
목록
찾아주셔서 감사합니다. Since 2012