jQuery โฮเวอร์ ()เมธอด

❮ วิธีการจัดกิจกรรม jQuery

ตัวอย่าง

เปลี่ยนสีพื้นหลังของ <p> องค์ประกอบเมื่อตัวชี้เมาส์วางอยู่เหนือมัน:

$("p").hover(function(){
  $(this).css("background-color", "yellow");
  }, function(){
  $(this).css("background-color", "pink");
});

ความหมายและการใช้งาน

วิธีการ hover() ระบุสองฟังก์ชั่นที่จะทำงานเมื่อตัวชี้เมาส์วางเมาส์เหนือองค์ประกอบที่เลือก

เมธอดนี้ทริกเกอร์ทั้งเหตุการณ์mouseenter และmouseleave

หมายเหตุ:หากมีการระบุฟังก์ชันไว้เพียงฟังก์ชันเดียว ฟังก์ชันจะถูกเรียกใช้สำหรับทั้งเหตุการณ์ mouseenter และ mouseleave


ไวยากรณ์

$(selector).hover(inFunction,outFunction)

Parameter Description
inFunction Required. Specifies the function to run when the mouseenter event occurs
outFunction Optional. Specifies the function to run when the mouseleave event occurs

❮ วิธีการจัดกิจกรรม jQuery