You need only to bind your element to a couple of events.
$("#slider").hover(
function(){
$(this).addClass('is-hover'); // you can use every class name you want of course
},
function(){
$(this).removeClass('is-hover');
}
);
or, in a more concise way
$("#slider").hover(
function(){
$(this).toggleClass('is-hover'); // you can use every class name you want of course
}
);
In this way every time the mouseenter
event is fired you will add a is-hover
class to your element and, when the mouseleave
event is fired, you will remove the class.
In your if statement you will have to change only:
if ( qactive == 0 && !($("#slider").hasClass('is-hover')) ) {
That's it.
Please note that you will have to adapt this example to your code, of course. Here I'm only assuming what you could need, since I can't see your code.
active
to the element, then check for that class in your if statement. – Wimberly:hover
, because it would require adding lots of handlers to the page (every element would need event hooks because jQuery doesn't know which ones you might check in the future), generally slowing everything down. – Monophagous.is(':hover')
in the previous jQuery versions?" – Chiu