在我看来,您的代码足够有效,因此您需要做的只是添加一个类以查看它是否被点击而不是停止悬停的动作。
jQuery:
$("#down").hover(
function() {
$(this).stop().animate({top:0},200);
},
function() {
// this will alert the situation for you to understand
alert($(this).hasClass("isDown"));
// if its clicked than do not move!
if ($(this).hasClass("isDown") == false) {
$(this).stop().animate({top:-5},220);
}
}
);
$("#down").click(
function() {
$("#DropUp").stop().animate({bottom:-250},220);
// Add a class to see if its clicked
$(this).toggleClass("isDown");
}
);
在你的小提琴周围工作:http: //jsfiddle.net/9DN52/14/
编辑:
我还解决了几个错误,修复了一些代码,添加了描述,我认为您真正想要做的是:
jQuery:
// Actually you can do this with css transition
// Remove these descriptions for a cleaner looking code
$("#down").hover(
function() { $(this).stop().animate({top:0},200); },
function() {
// if its clicked than do not move!
if ($(this).hasClass("isDown") == false) {
$(this).stop().animate({top:-5},220);
}
}
);
// Instead of toggle simple click action is enough
$("#down").click( function() {
// Thanks to class selector now we know
// if its clicked or down, so we know what to do..
if ($("#down").hasClass("isDown") == false) {
$("#DropDown").stop().animate({top:0},250);
// if footer is up already this will hide it
$("#DropUp").stop().animate({bottom:-250},220);
$("#up").removeClass("isUp");
} else {
$("#DropDown").stop().animate({top:-250},220);
}
// Each click should change the down situation
$("#down").toggleClass("isDown");
});
// Instead of toggle simple click action is enough
$("#up").click( function() {
// If its up already
if ($(this).hasClass("isUp") == false) {
$("#DropUp").stop().animate({bottom:0},250);
// if header is down already this will hide it
$("#DropDown").stop().animate({top:-250},220);
$("#down").stop().animate({top:-5},220).removeClass("isDown");
} else {
$("#DropUp").stop().animate({bottom:-250},220);
}
// Each click should change the up situation
$("#up").toggleClass("isUp");
});
小提琴:http: //jsfiddle.net/9DN52/43/