mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-18 15:00:23 +00:00
115 lines
No EOL
5.1 KiB
HTML
115 lines
No EOL
5.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang='en'><head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1"><meta http-equiv='content-type' content='text/html; charset=UTF-8' /></head><body>
|
|
<div data-role="page">
|
|
<div data-role="header">
|
|
<h1>.mouseenter()</h1>
|
|
|
|
</div>
|
|
<div data-role="content" data-theme="c" id="mouseenter1">
|
|
<h2 class="jq-clearfix roundTop section-title">
|
|
<span class="name">.mouseenter( handler(eventObject) )</span> <span class="returns">Returns: <a class="return" href="http://docs.jquery.com/Types#jQuery">jQuery</a></span>
|
|
</h2>
|
|
<div class=" entry-details">
|
|
<p class="desc"><strong>Description: </strong>Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element.</p>
|
|
<ul class="signatures">
|
|
<li class="signature" id="mouseenter-handlereventObject">
|
|
<h4 class="name">
|
|
<span class="versionAdded">version added: <a href="/category/version/1.0/">1.0</a></span>.mouseenter( handler(eventObject) )</h4>
|
|
<p class="arguement"><strong>handler(eventObject)</strong>A function to execute each time the event is triggered.</p>
|
|
</li>
|
|
<li class="signature" id="mouseenter"><h4 class="name">
|
|
<span class="versionAdded">version added: <a href="/category/version/1.0/">1.0</a></span>.mouseenter()</h4></li>
|
|
</ul>
|
|
<div class="longdesc">
|
|
<p>This method is a shortcut for <code>.bind('mouseenter', handler)</code> in the first variation, and <code>.trigger('mouseenter')</code> in the second.</p>
|
|
<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 sent to an element when the mouse pointer enters the element. Any HTML element can receive this event.</p>
|
|
<p>For example, consider the HTML:</p>
|
|
<pre><div id="outer">
|
|
Outer
|
|
<div id="inner">
|
|
Inner
|
|
</div>
|
|
</div>
|
|
<div id="other">
|
|
Trigger the handler
|
|
</div>
|
|
<div id="log"></div></pre>
|
|
<p class="image"><img src="http://api.jquery.com/images/0042_05_08.png" alt=""></p>
|
|
<p>The event handler can be bound to any element:</p>
|
|
<pre>$('#outer').mouseenter(function() {
|
|
$('#log').append('<div>Handler for .mouseenter() called.</div>');
|
|
});</pre>
|
|
<p>Now when the mouse pointer moves over the <span class="output">Outer</span> <code><div></code>, the message is appended to <code><div id="log"></code>. We can also trigger the event when another element is clicked:</p>
|
|
<pre>$('#other').click(function() {
|
|
$('#outer').mouseenter();
|
|
});</pre>
|
|
<p>After this code executes, clicks on <span class="output">Trigger the handler</span> will also append the message.</p>
|
|
<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 <span class="output">Inner</span> 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 <span class="output">Outer</span> element, but not the <span class="output">Inner</span> element.</p>
|
|
</div>
|
|
<h3>Example:</h3>
|
|
<div id="entry-examples" class="entry-examples"><div id="example-0">
|
|
<h4><span class="desc">Show texts when mouseenter and mouseout event triggering.
|
|
mouseover fires when the pointer moves into the child element as well, while mouseenter fires only when the pointer moves into the bound element.</span></h4>
|
|
<pre><code class="example demo-code"><!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<style>
|
|
div.out {
|
|
width:40%;
|
|
height:120px;
|
|
margin:0 15px;
|
|
background-color:#D6EDFC;
|
|
float:left;
|
|
}
|
|
div.in {
|
|
width:60%;
|
|
height:60%;
|
|
background-color:#FFCC00;
|
|
margin:10px auto;
|
|
}
|
|
p {
|
|
line-height:1em;
|
|
margin:0;
|
|
padding:0;
|
|
}
|
|
</style>
|
|
<script src="http://code.jquery.com/jquery-latest.js"></script>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="out overout"><p>move your mouse</p><div class="in overout"><p>move your mouse</p><p>0</p></div><p>0</p></div>
|
|
|
|
<div class="out enterleave"><p>move your mouse</p><div class="in enterleave"><p>move your mouse</p><p>0</p></div><p>0</p></div>
|
|
|
|
|
|
<script>
|
|
var i = 0;
|
|
$("div.overout").mouseover(function(){
|
|
$("p:first",this).text("mouse over");
|
|
$("p:last",this).text(++i);
|
|
}).mouseout(function(){
|
|
$("p:first",this).text("mouse out");
|
|
});
|
|
|
|
var n = 0;
|
|
$("div.enterleave").mouseenter(function(){
|
|
$("p:first",this).text("mouse enter");
|
|
$("p:last",this).text(++n);
|
|
}).mouseleave(function(){
|
|
$("p:first",this).text("mouse leave");
|
|
});
|
|
|
|
</script>
|
|
</body>
|
|
</html></code></pre>
|
|
<h4>Demo:</h4>
|
|
<div class="demo code-demo"></div>
|
|
</div></div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body></html> |