Reputation: 2645
I am trying to do some thing I'd like to think is simple.
animate a partially hidden element on hover, then when i click it, close it.
$('#call-to-action').hover(function(){
$('#call-to-action').animate({
right: '0px'
}, 1000);
$('.cta-open').hide();
$('.cta-close').show();
});
$('.cta-close').click(function(){
$('#call-to-action').animate({
right: '-364px'
}, 1000);
$('.cta-close').hide();
$('.cta-open').show();
stop();
});
the fiddle has the code I am using as well as the elements.
any ideas?
Upvotes: 0
Views: 197
Reputation: 207891
Change .hover()
to .mouseenter()
Since you're only passing a single function to hover, it gets executed when the mouse enters OR leaves the element.
$(document).ready(function () {
$('#call-to-action').mouseenter(function () {
$('#call-to-action').animate({
right: '0px'
}, 1000);
$('.cta-open').hide();
$('.cta-close').show();
});
$('.cta-close').click(function () {
$('#call-to-action').animate({
right: '-364px'
}, 1000);
$('.cta-close').hide();
$('.cta-open').show();
stop();
});
});
Upvotes: 1