Home >Web Front-end >JS Tutorial >jQuery mouse event summary_jquery

jQuery mouse event summary_jquery

WBOY
WBOYOriginal
2016-05-16 15:41:351084browse

Mouse events are triggered when the user moves the mouse cursor or clicks with any mouse button.

1. Click event : Triggered when the left mouse button is clicked

 $('p').click(function(){});

Example:

$('p').click(function(){
        alert('click function is running !');
       });

2. dbclick event : triggered when two clicks are made in quick succession

 $('p').dbclick(function(){});

Example:

$("button").dblclick(function(){
 $("p").slideToggle();
});

3. mousedown event : triggered when the mouse is pressed

 $('p').mousedown(function(){});

Example

$("button").mousedown(function(){
 $("p").slideToggle();
});

4. mouseup event : triggered when the mouse is released

 $('p').mouseup(function(){});

Example:

$("button").mouseup(function(){
 $("p").slideToggle();
});

5. mouseover event : triggered when the mouse moves from one element to another

 mouseout event: triggered when the mouse moves out of an element

 $('p').mouseover(function(){});

$('p').mouseout(function(){});

Example:

$("p").mouseover(function(){
 $("p").css("background-color","yellow");
});
$("p").mouseout(function(){
 $("p").css("background-color","#E9E9E4");
});

6. mouseenter event : triggered when the mouse moves into an element

mouseleave event: triggered when the mouse moves out of an element

 $('p').mouseenter(function(){});

$('p').mouseleave(function(){});

Example

$("p").mouseenter(function(){
 $("p").css("background-color","yellow");
});
$("p").mouseleave(function(){
 $("p").css("background-color","#E9E9E4");
});

7. Hover event

 $('p').hover(
function(){},
function(){}
);

Example

$(".table_list tr").hover( 
function () { 
$(this).addClass("hover"); 
}, 
function () { 
$(this).removeClass("hover"); 
} 

); 

8. toggle event : mouse click switching event

 $('p').toggle(
function(){},
function(){}
);

Example

$("p").toggle(
 function(){
 $("body").css("background-color","green");},
 function(){
 $("body").css("background-color","red");},
 function(){
 $("body").css("background-color","yellow");}
);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn