jqueryUI autocomplete menu show effect

好久不见. 提交于 2019-12-05 12:26:39

Since you're using HTML5 there you could use CSS Transitions to do the Job.

Add/Remove a class on the open/close events of the Autocomplete Instance:

$( "#tags" ).autocomplete({
  source: availableTags,
  open: function () { $('ul.ui-autocomplete').addClass('opened') },
  close: function () { 
    $('ul.ui-autocomplete')
      .removeClass('opened')
      .css('display','block'); 
  },
});

Then add following CSS:

.ui-autocomplete {
    opacity: 0;
    display: none;
    transition: opacity 1s;
    -moz-transition: opacity 1s;
    -webkit-transition: opacity 1s;
    -o-transition: opacity 1s;
}

.ui-autocomplete.opened {
    opacity: 1;
}

​ Though I suppose you could do just the same method with the jQuery UI Fade to class method. Note: Will produce weird results when there's more than 1 Autocomplete on a page.

Example on JSFiddle

What about this? (no CSS needed)

$( "#tags" ).autocomplete({
    source: availableTags,
    open: function () { $('ul.ui-autocomplete').hide().fadeIn() },
    close: function () { $('ul.ui-autocomplete').show().fadeOut() }
});

If it helps, i've created a function that applies with each autocomplete in the project, maybe it can be improved, but it works

$(document).on('autocompleteopen', function(event, ui) {
  $(event.target).autocomplete('widget').hide().fadeIn('fast');
}).on('autocompleteclose', function(event, ui) {
  $(event.target).autocomplete('widget').show().fadeOut('fast');
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!