如何将延迟插入到此代码段中,以便在用户完成输入后才会触发?
JS
gridContainer = $('#shuffleContainer');
var sizer = gridContainer.find('.col-md-4');
$('.js-shuffle-search').on('keyup change', function () {
var val = this.value.toLowerCase();
gridContainer.shuffle('shuffle', function ($el, shuffle) {
// Only search elements in the current group
if (shuffle.group !== 'all' && $.inArray(shuffle.group, $el.data('groups')) === -1) {
return false;
}
var text = $.trim($el.find('.picture-item__title').text()).toLowerCase();
return text.indexOf(val) !== -1;
});
});
JS DELAY
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$('input').keyup(function() {
delay(function(){
alert('Time elapsed!');
}, 1000 );
});