點擊動作,我有一些功能是這個樣子:重新啓動功能使用jQuery
var live_search_list = $('.live_search_list ul'),
active_search_element = live_search_list.find('li.active'),
search_element = live_search_list.find('li'),
jsPane = $('.jspPane');
$('.bottom_search').click(function(){
if (!search_element.last().hasClass('active')) {
active_search_element.removeClass('active');
active_search_element.next('li').addClass('active');
jsPane.animate({top:"-=95px"});
}
});
$('.top_search').click(function(){
if (!search_element.first().hasClass('active')) {
active_search_element.removeClass('active');
active_search_element.prev('li').addClass('active');
jsPane.animate({top:"+=95px"});
}
});
所以,問題開始第一次點擊之後,我只有一個動作 - 這個動畫。第一次點擊功能後,不再檢查我的情況,並且不會更改,刪除類active
。每次點擊這個按鈕後我怎樣才能重新啓動這個功能?
你想['停止()'](http://api.jquery.com/停止/)動畫? – epascarello
我想在每次點擊後檢查我的情況,現在在第一次點擊一切正常後,但在它之後我只有動畫動作... – Lukas
您確定'search_element'和'active_search_element'是第二次和以後的有效元素點擊? +1對於epascarello所說的 - 除了任何東西 - 在再次開始動畫之前停止()總是個好主意,否則,如果用戶在短時間內點擊幾次,你的動畫就會排隊等候,一切都會變得很詭異。 – WTK