简体   繁体   English

jQuery Autocomplete Plugin 1.2.3响应宽度下拉列表

[英]jQuery Autocomplete Plugin 1.2.3 responsive width dropdown

Has anyone used this autocomplete plugin currently in github? 有人在github中使用过此自动完成插件吗? when you call the autocomplete function you can pass the width variable in pixels of the dropdown box, ie "width:200,". 当您调用自动完成功能时,您可以通过下拉框的像素传递width变量,即“ width:200”。

I want the dropdown to be the same size as the input field. 我希望下拉列表与输入字段的大小相同。 This works fine when you know the width of the input field, but when using a responsive input field which changes width depending on the device your using, how would you go about setting this to the width of the current input field? 当您知道输入字段的宽度时,这很好用,但是当使用响应输入字段时,该输入字段根据您使用的设备而改变宽度,您将如何将其设置为当前输入字段的宽度?

If you're talking about this plugin: https://github.com/devbridge/jQuery-Autocomplete . 如果您正在谈论此插件: https : //github.com/devbridge/jQuery-Autocomplete

I ran into the same problem and made a workaround. 我遇到了同样的问题,并提出了解决方法。 I set the width as a fixed value like this: 我将宽度设置为固定值,如下所示:

$('#input').autocomplete({
    width: 780
});

Then whenever the page resizes I run this function: 然后,每当页面调整大小时,我都会运行以下功能:

function page_resize(){
    $('.autocomplete-suggestions').css('width', $('#input').width());
}

I tried quite a few different ways to solve this. 我尝试了许多不同的方法来解决此问题。 I think the best solution I have come across is to set the width to very small size and it will actually resize/adjust to the larger then assigned width. 我认为我遇到的最好的解决方案是将宽度设置为非常小的尺寸,并且实际上可以将尺寸调整/调整为更大然后分配的宽度。

Example CSS: CSS示例:

.ui-autocomplete {
    max-height: 400px;
    width: 200px; /* just setting it very small it will resize to the input field*/
    overflow-y: auto;
    /* prevent horizontal scrollbar */
    overflow-x: hidden;
    z-index: 1000;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM