Jquery: function running before fadeOut Complete

故事扮演 提交于 2019-12-06 11:00:56

This will run for each of the .content_box elements...and the hidden ones will finish their animation immediately, so you want is this:

$("#events_link").click(function() {
   $("#content > .content_box:visible").fadeOut(fadetime, function() {
      $("#events").fadeIn(fadetime);
   });
   return false
});

The important change is the :visible selector, so only the visible one is faded out...and triggers the callback to show the next one.

windows.setTimeout is not always useful because sometimes the process might take more time than the timeout you have set. So it's better to use following code to run fadeIn only after fadeOut is done.

$("#events_link").click(function() {
   $.when(
      // Your function which you want to finish first
      // $("#content").children(".content").fadeOut(fadetime)
   ).done(function() {
      // The function which you want to run after finishing the previous function
      // $("#events").fadeIn(fadetime);
   });
   return false
});*

The current version of your page doesn't appear to be working at all because you have something like

$("#content").children(".content")

instead of

$('#content').children('.content_box')

Fix that and it will be easier to troubleshoot...

EDIT (now that above fix is done):

It does seem like the fadeOut function is not working quite as documented, at least in Firefox 3.5, in regard to callbacks. I think what you probably want can be accomplished by using a little plain-old javascript:

$('#content').children('.content_box').fadeOut(fadetime);
window.setTimeout(function () { $('#events').fadeIn(fadetime); }, fadetime + 100);
return false;

I think that will more likely accomplish what you want by trying to ensure that the old content is gone and no longer actually taking up space before fading in the new content. Let us all know if it works for you.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!