I need to do an animation of loading directly in the list of items, like this:SnapShot
I used jQuery UI
, here the code:
$(document).ready(function() {
$("#cities").autocomplete({
source: function(request, response) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
$.ajax({
url: "file.json",
dataType: 'json'
}).done(function(data){
response($.map(data, function(v,i){
var text = v.City;
if(text && ( !request.term || matcher.test(text))){
return {
label: v.City,
value: v.City
};
}
}));
});
},
search: function(event, ui){
//$('#ui-id-1').addClass('ui-menu ui-widget ui-widget-content ui-autocomplete ui-front').show();
},
open: function(event, ui) {
// $('#ui-id-1').removeClass('ui-menu ui-widget ui-widget-content ui-autocomplete ui-front').hide();
},
close: function(event, ui) {
/*.......*/
},
minLength: 1,
autoFocus: true,
crossDomain: true,
response: function(event, ui) {
if (!ui.content.length) {
ui.content.push({label:"Not found"});
}
}
});
});
Html:
<div class="wrap">
<label for="cities">Cities: </label>
<input id="cities">
<ul tabindex="0" id="ui-id-1" style="display: none;" ><li class="ui-menu-item "><div tabindex="-1" id='ui-id-3' class="ui-menu-item-wrapper">Seeking</div></li></ul>
</div>
I've read that I can use search
and open
to manipulate with elements during loading of the source, but there is a problem:
I tried to use .addClass
and .show()
methods to display the list. It worked, but the element had the wrong position: It was on the top of page - styles for it didn't calculate at all.
How can it be fixed or are there any other ways?