QUIZGUM

Coding Class

Quizgum : mouse on event

Mouse Event

In the last lesson, when I clicked something happened. This time, let's do something by hovering the mouse pointer.

mouseenter();

Just change click() in the last lesson to mouseenter().

  1. $('.class_name').mouseenter();

Create event when mouse pointer leaves an element

mouseleave();

Use mouseleave(); to generate an event when the mouse pointer leaves an element.

  1. $('.class_name').mouseleave();

How to use

Let's test mouseenter() and mouseleave()

test it

Hover your mouse pointer to see what phrases are coming out.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>jQuery</title>
  6. <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.0.min.js" ></script>
  7. <script type="text/javascript">
  8. $(function(){
  9. $('.yellow_circle').mouseenter(function(){
  10. $('.yellow_circle_word').text('The mouse pointer is in a yellow circle.');
  11. });
  12. $('.yellow_circle').mouseleave(function(){
  13. $('.yellow_circle_word').text('The mouse pointer has left the yellow circle.');
  14. });
  15. });
  16. </script>
  17. </head>
  18. <body>
  19. <div class="yellow_circle" style="width:40px;height:40px;border-radius:20px;background:yellow"></div>
  20. <p class="yellow_circle_word">test it.</p>
  21. </body>
  22. </html>

Here's the text() that I see for the first time. This function is used to change or get the text. ^-^

Don't bother. In this tutorial, you only need to look at mouseenter() and mouseleave().

mouseenter()과 mouseleave()를 함께 사용하는 hover()도 있습니다.

hover

How to use hover()

  1. $('.class_Name').hover();

example

  1. $('.class_Name').hover(function(){
  2. $('.class_Name').css('border','5px solid blue');
  3. },
  4. function(){
  5. $('.class_Name').css('border','5px solid red');
  6. }
  7. );

그럼 실제 만들어 봅시다.

HTML

  1. <div class="hover1"></div>

CSS

  1. .hover1{width:100px; height:50px; background:yellow}

jQuery

  1. var hover1 = $('.hover1');
  2. hover1.hover(function(){
  3. hover1.css('border','5px solid blue');
  4. },
  5. function(){
  6. hover1.css('border','5px solid red');
  7. });

Source

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>jQuery</title>
  6. <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.0.min.js" ></script>
  7. <script type="text/javascript">
  8. $(function(){
  9. var hover1 = $('.hover1');
  10. hover1.hover(function(){
  11. hover1.css('border','5px solid blue');
  12. },function(){
  13. hover1.css('border','5px solid red');
  14. });
  15. });
  16. </script>
  17. <style>
  18. .hover1{width:100px; height:50px; background:yellow}
  19. </style>
  20. </head>
  21. <body>
  22. <div class="hover1"></div>
  23. </div>
  24. </body>
  25. </html>