Reputation: 3193
I have a button with a hover effect:
$('.donations').hover(function() {
$(this).find('#donate_expand_top').hide().stop(true, true).animate({
height: 'toggle'
}, {
duration: 200
});
I now need to add a click effect on the same button so that it's touch-friendly. I understand the concept easy enough using $('.donations').click(function(){...
but the problem is in combining these two effects it doesn't work correctly. As soon as I click on the button, i'm also hovering, so it tries to fire both and neither works.
Is there an easy solution to this?
Upvotes: 1
Views: 231
Reputation: 10743
This is not the most elegant solution, but it keeps track of user's interaction with the button and fires the click event on hover:
var interactingWithBtn = false;
$('#donate_expand_top').hover(function() {
if(!interactingWithBtn) {
interactingWithBtn = true;
$('#donate_expand_top').trigger('click');
}
},
function() {
interactingWithBtn = false;
});
$('#donate_expand_top').click(function() {
if(!interactingWithBtn)
interactingWithBtn = true;
$(this).find('#donate_expand_top').hide().stop(true, true).animate({
height: 'toggle'
}, {
duration: 200
});
});
Upvotes: 0