如果我使用的初始選擇器包含children()
,如何將回調函數添加到slideUp()
函數?當初始選擇器包含子時,Jquery slideUp回調函數
$('.homebuttonbutton').hover(function() {
$(this).stop().children('.homebuttonaction').slideDown();
$(this).children('.homebuttonlabel').addClass('whitebutton');
}, function() {
$(this).stop().children('.homebuttonaction').slideUp(300, function() {
$(this).children('.homebuttonlabel').removeClass('whitebutton');
});
//$(this).children('.homebuttonlabel').removeClass('whitebutton');
});
那麼理想,徘徊的時候,孩子.homebuttonaction
向下滑動,並具有.whitebutton
類添加,然後當未徘徊,在.homebuttonaction
向上滑動和.whitebutton
類被刪除。
我希望能夠在slideUp
動畫完成後刪除該類,但我不確定如何「選擇」它,因爲初始選擇器使用children
作爲回調函數。
有將要多.homebuttonaction
類,所以我不能只用
$('.homebuttonaction').removeClass('.whitebutton');
因爲那將適用於每一個,對不對?回撥函數是否將$(this)
視爲首先選擇的項目,還是將當前選定的項目視爲children()
?
感謝您的幫助,所以。
編輯 這裏是我的小提琴 - http://jsfiddle.net/kcxWc/ - 你可以看到,類不會被刪除,因爲它應該是在後效果效果基本show結束。我相信這是一個選擇問題...
你不應該使用'$(本)''裏面,而不是callback',你可以在外面緩存像' var $ this = $(this)'然後使用'$ this'而不是'$(this)'。類似於這個的答案是[這裏](http://stackoverflow.com/questions/15058159/jquery-dropdown-on-click/15058628#15058628)。 – 2013-02-25 20:39:40
代碼有問題嗎?什麼不像你期望的那樣發生? – Andre 2013-02-25 20:42:32
@刪除類的回調函數不起作用。我相信選擇器是不正確的。 – RCNeil 2013-02-25 20:45:09