When the mouse moves in, the jQuery trigger enters the status.
$(".test").bind("mouseenter mouseout", function(event) {
$(this).toggleClass("entered");
alert("mouse position (" + event.pageX + "," + event.pageY + ")");
});
.entered {
font-size: 36px;
width: 200px;
height: 100px;
border: 2px solid black;
}
.test {
border: 2px solid red;
background: #fdd;
width: 60px;
height: 60px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="test">please move in</div>
In my code snippet, I discovered two issues:
The entered status only applies
font-size: 36px;
, why do
not take effect?width: 200px; height: 100px; border: 2px solid black;
The
alert
pops up before$(this).toggleClass("entered");
is completed. How can I ensure that thealert
executes after$(this).toggleClass("entered");
has completely finished?