在我看來你的代碼是efficent足夠,所以你需要做的只是增加一個類來看看它的點擊比它停止懸停的行動是什麼。
的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/
謝謝!我看到的兩個錯誤是在單擊頂部按鈕後,必須單擊每個按鈕兩次才能使該div上/下。此外,只有當您按下該按鈕時,頂部的按鈕纔會返回,但如果您單擊底部按鈕則不會。基本上,如果您單擊頂部按鈕並且它下降並且內容向下滑動,則會修復,然後如果您單擊底部的按鈕,則會將內容備份並將頂部按鈕移回。謝謝,雖然它現在真的很好! – mike
@mike我更新了我提供的問題的答案。 –
嘿男人謝謝。我真的很感激這個腳本非常棒,並且做了一切必要的事情,你是男人! – mike