control-freak-ide/Control-Freak-Documentation/jQuery/docs/entries/mouseenter.json
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

1 line
4.2 KiB
JSON

{"name":"mouseenter","type":"method","title":".mouseenter()","deprecated":null,"removed":null,"desc":"Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element.","categories":["events/mouse-events","version/1.0","version/1.4.3"],"entries":[{"return":"jQuery","signatures":[{"added":"1.0","argument":{"desc":"A function to execute each time the event is triggered.","name":"handler(eventObject)","type":"Function"}},{"added":"1.4.3","argument":[{"desc":"An object containing data that will be passed to the event handler.","name":"eventData","type":"PlainObject","optional":"true"},{"desc":"A function to execute each time the event is triggered.","name":"handler(eventObject)","type":"Function"}]},{"added":"1.0"}],"examples":{"desc":"Show texts when mouseenter and mouseout event triggering.\n <code>mouseover</code> fires when the pointer moves into the child element as well, while <code>mouseenter</code> fires only when the pointer moves into the bound element.","css":"\n div.out {\n width: 40%;\n height: 120px;\n margin: 0 15px;\n background-color: #d6edfc;\n float: left;\n }\n div.in {\n width: 60%;\n height: 60%;\n background-color: #fc0;\n margin: 10px auto;\n }\n p {\n line-height: 1em;\n margin: 0;\n padding: 0;\n }\n","code":"\nvar i = 0;\n$( \"div.overout\" )\n .mouseover(function() {\n $( \"p:first\", this ).text( \"mouse over\" );\n $( \"p:last\", this ).text( ++i );\n })\n .mouseout(function() {\n $( \"p:first\", this ).text( \"mouse out\" );\n });\n\nvar n = 0;\n$( \"div.enterleave\" )\n .mouseenter(function() {\n $( \"p:first\", this ).text( \"mouse enter\" );\n $( \"p:last\", this ).text( ++n );\n })\n .mouseleave(function() {\n $( \"p:first\", this ).text( \"mouse leave\" );\n });\n","html":"\n<div class=\"out overout\">\n <p>move your mouse</p>\n <div class=\"in overout\"><p>move your mouse</p><p>0</p></div>\n <p>0</p>\n</div>\n\n<div class=\"out enterleave\">\n <p>move your mouse</p>\n <div class=\"in enterleave\"><p>move your mouse</p><p>0</p></div>\n <p>0</p>\n</div>\n"},"longdesc":"\n <p>This method is a shortcut for <code>.on( \"mouseenter\", handler )</code> in the first two variations, and <code>.trigger( \"mouseenter\" )</code> in the third.</p>\n <p>The <code>mouseenter</code> JavaScript event is proprietary to Internet Explorer. Because of the event's general utility, jQuery simulates this event so that it can be used regardless of browser. This event is sent to an element when the mouse pointer enters the element. Any HTML element can receive this event.</p>\n <p>For example, consider the HTML:</p>\n <pre><code>\n&lt;div id=\"outer\"&gt;\n Outer\n &lt;div id=\"inner\"&gt;\n Inner\n &lt;/div&gt;\n&lt;/div&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n&lt;div id=\"log\"&gt;&lt;/div&gt;</code></pre>\n <p class=\"image\">\n <img src=\"/resources/0042_05_08.png\" alt=\"\"/>\n </p>\n <p>The event handler can be bound to any element:</p>\n <pre><code>\n$( \"#outer\" ).mouseenter(function() {\n $( \"#log\" ).append( \"&lt;div&gt;Handler for .mouseenter() called.&lt;/div&gt;\" );\n});\n </code></pre>\n <p>Now when the mouse pointer moves over the <samp>Outer</samp> <code>&lt;div&gt;</code>, the message is appended to <code>&lt;div id=\"log\"&gt;</code>. You can also trigger the event when another element is clicked:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#outer\" ).mouseenter();\n});\n </code></pre>\n <p>After this code executes, clicks on <samp>Trigger the handler</samp> will also append the message.</p>\n <p>The <code>mouseenter</code> event differs from <code>mouseover</code> in the way it handles event bubbling. If <code>mouseover</code> were used in this example, then when the mouse pointer moved over the <samp>Inner</samp> element, the handler would be triggered. This is usually undesirable behavior. The <code>mouseenter</code> event, on the other hand, only triggers its handler when the mouse enters the element it is bound to, not a descendant. So in this example, the handler is triggered when the mouse enters the <samp>Outer</samp> element, but not the <samp>Inner</samp> element.</p>\n "}]}