In a small application I check if the cursor is over this object. In chrome and firefox, a test like if($(this).is(":hover"))
works normally, but in safari this code always returns false
.
Can anyone tell me how to solve this nuance?
In a small application I check if the cursor is over this object. In chrome and firefox, a test like if($(this).is(":hover"))
works normally, but in safari this code always returns false
.
Can anyone tell me how to solve this nuance?
There is an alternative in the form of mouseover
and mouseleave
events that work fine in Safari (5.1.7 for Windows). Here is an example:
$('.test').on('mouseenter', function() { $(this).css('background-color', '#eee'); }).on('mouseleave', function() { $(this).removeAttr('style'); });
.test { border: 1px solid #000; width: 100px; height: 100px; margin: 25px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class='test'></div>
Still read the article: " Mouse: move mouseover / out, mouseenter / leave ".
It will help to better understand these events.