Metoda jQuery hover() .
Příklad
Změňte barvu pozadí prvku <p>, když na něj najedete ukazatelem myši:
$("p").hover(function(){
$(this).css("background-color", "yellow");
}, function(){
$(this).css("background-color", "pink");
});
Definice a použití
Metoda hover() určuje dvě funkce, které se mají spustit, když ukazatel myši najede na vybrané prvky.
Tato metoda spouští události mouseenter i mouseleave .
Poznámka: Pokud je zadána pouze jedna funkce, bude spuštěna pro události mouseenter i mouseleave.
Syntax
$(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 |