Jquery - Show the number of times mouseout and mouseleave events are triggered.


SUBMITTED BY: jlolk3r

DATE: Jan. 20, 2016, 1:31 a.m.

FORMAT: HTML

SIZE: 1.3 kB

HITS: 1234

  1. <html lang="en">
  2. <head>
  3. <meta charset="utf-8">
  4. <title>mouseout demo</title>
  5. <style>
  6. div.out {
  7. width: 40%;
  8. height: 120px;
  9. margin: 0 15px;
  10. background-color: #d6edfc;
  11. float: left;
  12. }
  13. div.in {
  14. width: 60%;
  15. height: 60%;
  16. background-color: #fc0;
  17. margin: 10px auto;
  18. }
  19. p {
  20. line-height: 1em;
  21. margin: 0;
  22. padding: 0;
  23. }
  24. </style>
  25. <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  26. </head>
  27. <body>
  28. <div class="out overout">
  29. <p>move your mouse</p>
  30. <div class="in overout"><p>move your mouse</p><p>0</p></div>
  31. <p>0</p>
  32. </div>
  33. <div class="out enterleave">
  34. <p>move your mouse</p>
  35. <div class="in enterleave"><p>move your mouse</p><p>0</p></div>
  36. <p>0</p>
  37. </div>
  38. <script>
  39. var i = 0;
  40. $( "div.overout" )
  41. .mouseout(function() {
  42. $( "p:first", this ).text( "mouse out" );
  43. $( "p:last", this ).text( ++i );
  44. })
  45. .mouseover(function() {
  46. $( "p:first", this ).text( "mouse over" );
  47. });
  48. var n = 0;
  49. $( "div.enterleave" )
  50. .on( "mouseenter", function() {
  51. $( "p:first", this ).text( "mouse enter" );
  52. })
  53. .on( "mouseleave", function() {
  54. $( "p:first", this ).text( "mouse leave" );
  55. $( "p:last", this ).text( ++n );
  56. });
  57. </script>
  58. </body>
  59. </html>

comments powered by Disqus