开发者

How can I apply a loading gif animation to my autosuggest?

开发者 https://www.devze.com 2022-12-18 17:51 出处:网络
I\'m so lucky to have my solution on an US server, while my audience is located in Scandinavia (on the other side of the pond).

I'm so lucky to have my solution on an US server, while my audience is located in Scandinavia (on the other side of the pond).

This makes the respons time a bit slow, and not ideal when I'm using AutoComplete for my search box.

To give the user some feedback, I want to display a animated loading GIF.

The problem is that I don't know how to initiate it before callback. The aniamtion should start when AutoComplete searches the DB, and stop when DB search is finished.

My javascript looks something like this:

jQuery(document).ready(function() {
    var options = autosuggestOptions();
    var response = new bsn.AutoSuggest('mySearchBox', options);
});

  fu开发者_如何转开发nction autosuggestOptions()
  {
    var options = {
        script:"wp-content/themes/test/include/someFile.php?",
        varname:"input", minchars: 2, delay: 200, json:true, maxresults:15, timeout: 5000,
          callback: function (obj) { (.. do stuff here ..) }
    };
    return options;  
  } 

My animated gif is inside <div class="loader"></div>.

Suggestions anyone?


Immediately within autosuggestOptions(), show the div. Then hide it within the callback.

function autosuggestOptions() {
  // Show the loader
  $(".loader").fadeIn();
  var options = {
    callback: function(obj) {
      /* Safe to hide the loader */
      $(".loader").fadeOut();
    }
  };
}
0

精彩评论

暂无评论...
验证码 换一张
取 消