jQuery Tutorial #01 Mouse Events (Click , dblClick, mouseEnter, mouseLeave, mouseOver and Hover)
Repository
https://github.com/jquery/jquery
What Will I Learn?
I will learn in this tutorial the jquery events in particular the mouse events.
- The click and double click events.
- The mouseenter and mouseleave events.
- The mouseover event.
- The hover event.
Requirements
- Knowledge about HTML5 and CSS3
- Knowledge about jQuery
- A text editor like notpad ++
Difficulty
- Basic
Description
In this tutorial we will learn the jQuery events , the jQuery has 4 types of events we will take the first type ( Mouse Events ) .
- I created a table to organize the explanation and to clarify the points more, in the table I have 4 columns , each one contains an event
1- Click Event :
We can customize what will happen when we click on an element button for example or link or something else by the ' click event ' .
Before anything you must select the element by the $('element')
selector , after that we apply the .click()
event .
We pass a function as parameter for this method $('element').click(function () { // something here }));
And when you click on the element , the system will execute the //something here , it will execute the content of the function.
In the function you can do anything you need for the example that I explained I have show a list when I click on the button , and this is a benefit of clicking benefits.
My code :
/******* click event **********/
$('.btnClick').click(function () {
$('.listTest1').animate({
height: '80px'
}, 600);
$('.listTest1').css('visibility', 'visible');
});
2- Double Click Event :
The system will execute the content of the function just when we double the click on the element and for that we need the dblclick()
event .
$('element').dblclick(function () { //something here});
For the example that I mentioned when I double the click on the button, the list will appear , there is many examples to use the double click, let's just know that it's very important and very usable.
My code :
/******* double click event **********/
$('.btnDblClick').dblclick(function () {
$('.listTest2').animate({
height: '80px'
}, 600);
$('.listTest2').css('visibility', 'visible');
});
The result when we click on the first button and when we double the click on the second button :
3- MouseEnter Event :
This event is very important, we need it a lot in the sliders , images and portfolios ..etc , when we pass the mouse on the image the informations about the image will appear and it's a good effect .
You should firstly select the element $('element') then you need to use the event mouseenter() with the function as parameter $('element').mouseeneter(function () { //something here });
My code :
/**** MouseEnter event ****/
$('.tdImg1').mouseenter(function () {
$('.overley1').fadeIn(600);
});
The result :
4- MouseLeave Event :
This event is the contrary of the previous event , when we pass the mouse on the element the system will execute the mouseenter event and when we leave from the element the system will execute the mouseleave event.
$('element').mouseleave(function () { //something here});
We select the element firstly then we apply the event to disappear an element for example .
My code
/**** MouseLeave event ****/
$('.tdImg1').mouseleave(function () {
$('.overley1').fadeOut(600);
});
5- MouseOver Event :
This event is the same with the mouseenter event , when you enter the mouse on the element something will be applied.
$('element').mouseover(function () { //something here});
This is my code :
/******* MouseOver event **********/
$('.tdImg2').mouseover(function () {
$('.overley2').fadeIn(600);
});
6- Hover Event :
The hover event combine between the mouseenter and mouseleave events , it has two functions
$('element').hover(function () { //first function}, function () { //second function });
The first function equals to the mouseenter event and the second function equals to the mouseleave event.
My code :
/**** Hover ****/
$('.tdImg1').hover(function () {
$('.overley1').fadeIn(600);
}, function () {
$('.overley1').fadeOut(600);
});
Hi @alexandre-maxim,
Thank you for your contribution. This is the second of your series of tutorial and a good topic that you are doing.
For video tutorial, try to have a structured well prepared script with a clear outline so that your learner can follow along easily.
Also it is good to edit the video when you make mistake and not leave "sorry ...." and continue on without deleting that part. This can be quite annoying to students and videos are not done professionally.
Since English is not your first language, try to use simpler sentences both orally and in your text post. Run on sentences make it very difficult for people to follow and they need to read back and forth.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Thank you sir , I will prepare more my tutorials ..
You said " Also it is good to edit the video when you make mistake and not leave "sorry ...." and continue on without deleting that part. This can be quite annoying to students and videos are not done professionally. " and in the guidlines " videos should not contain any substantial pauses " , can I edit my video ?
✅ @alexendre-maxim, enjoy the vote!
Have you claimed your FREE Byteballs yet? Check out this post on how you can get $10-80 just for having a Steem account: https://steemit.com/steem/@berniesanders/get-free-byteballs-today-just-for-having-a-steem-account-usd10-80-in-free-coins
Thank you
Hey @alexendre-maxim
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Thank you