English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
마우스 포인터가 선택된 요소에��때 hover() 메서드는 실행할 두 가지 함수를 지정합니다。
이 메서드는 동시에 트리거합니다mouseenter와mouseleave이벤트。
hover() 메서드 호출은 간단합니다:;$(selector).mouseenter(function_in).mouseleave(function_out)
주의:단일 함수를 전달할 때 hover() 메서드는 mouseenter와 mouseleave 이벤트에 대한 함수를 실행합니다。
$(selector).hover(function_in, function_out)
마우스 포인터가 위에��때 모든 <p> 요소의 배경색을 변경합니다:
$("p").hover(function(){ $(this).css("background-color", "yellow"); }, function(){ $(this).css("background-color", "lightblue"); });테스트를 보고‹/›
특수 스타일을 추가하여 마우스 오버할 항목을 나열합니다:
$(document).ready(function(){ $("li").hover(function(){funcIn(this);}, function(){funcOut(this);}); }); function funcIn(x) { $(x).html("마우스<b>ENTER</b> 按下事件被触发"); $(x).css("background", "yellow"); } function funcOut(x) { $(x).html("마우스 떠나는 이벤트가 발생"); $(x).css("background", "white"); }테스트를 보고‹/›
하나의 함수만 지정하면 mouseenter와 mouseleave 이벤트 모두에 해당 함수가 실행됩니다:
$("div").hover(function(){ $(this).css("background", randColor()); }); // 랜덤한 색상을 가져오는 함수 function randColor() { return 'rgb(' + Math.floor(Math.random()*256) + ',' + Math.floor(Math.random()*256) + ',' + Math.floor(Math.random()*256) + ')'; }테스트를 보고‹/›
파라미터 | 설명 |
---|---|
function_in | 요소에 마우스 포인터가 오면 실행되는 기능 |
function_out | 요소에서 마우스 포인터가 나가면 실행되는 함수(선택 사항) |