fadeToggle jQuery callback before, not after
Is there a way 开发者_开发问答to assign a callback before the fade animation occurs in fadeToggle? I am adjusting scroll positions and would like to adjust it before the object appears, not after.
Call back gives you a way to perform something after the given action has completed. If you need to do something before operation (fading) just do it before calling the function itself.
would the fadeToggle
override be an option for you ? if so then click the link below :)
Override jQuery functions
All you need to do is call your function, or run any code, directly after fadeToggle:
element.fadeToggle('fast');
element.scrollTop(300);
This will immediately set the scroll position, and the fade affect will follow.
Here is what I specifically had: visible and hidden are elements I just named as vars.
visible.fadeToggle('fast', function() {
hidden.fadeToggle('fast');
hidden.scrollTop(top_value);
});
When visible is hidden, the callback is invoked and the hidden element becomes visible. The scroll position is set immediately after, so you see the change before the fade has completed. This way you have a fluid fade and keep the scroll positions of both elements the same.
精彩评论