What's the jquery way to make hover function execute once and then stop?
.one() didnt work..
$(".button-color-2").hover(
function (){
dosmth();
});
thank you
hover() is deprecated #66.
The hover() is an inbuilt method in jQuery which is used to specify two functions to start when mouse pointer move over the selected element. Syntax: $(selector). hover(Function_in, Function_out);
jQuery mouseover() Method Note: Unlike the mouseenter event, the mouseover event triggers if a mouse pointer enters any child elements as well as the selected element. The mouseenter event is only triggered when the mouse pointer enters the selected element. See the example at the end of the page for a demonstration.
Hover binds the handlers for Mouse Enter and Mouse Leave event and is not an event on its own. Hence, in order to have the same effect as Hover, you will have two binds that will trigger once.
$(".button-color-2").one("mouseenter mouseleave", function(e){
dosmth();
});
If you want to do different things on mouseenter and mouseleave, then bind two different handlers
$(".button-color-2").one("mouseenter", function(e){
dosmth1();
}).one("mouseleave", function(e){
dosmth2();
});
The other option would be to use Hover and then unbind it once you are done.
$('.button-color-2').hover(function() {
dosmth();
$(this).unbind('mouseenter mouseleave')
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With