css - 谷歌自动完成下拉位置问题
问题描述
我在我的 Angular 应用程序中使用NgxAutocomPlace模块,以下模块通过生成.pac-container
显示自动完成结果的方式与谷歌自动完成 API 一起使用。
问题是,在移动设备上,下拉菜单位于输入的上方而不是下方,并且对于最终用户来说是不可用的,它看起来像这样:
这是我的代码的样子:
<div class="container-indirizzo mb-3">
<label>Indirizzo di consegna</label>
<div class="inside-indirizzo">
<div class="indirizzo">
<input
*ngIf="addressOptions !== null"
type="text"
class="form-control"
required
placeholder="es. Via Disraeli"
formControlName="indirizzo"
ngxAutocomPlace
[options]="addressOptions"
(selectedPlace)="addressChange($event)"
/>
</div>
<div class="civico" *ngIf="isCivico">
<input type="text" class="form-control" formControlName="nciv" placeholder="N°" autofocus />
</div>
</div>
</div>
有没有办法在下面设置该下拉菜单的位置<input>
?
编辑1:
当虚拟键盘启动时,问题发生在滚动或移动设备上,因此问题是触发时设置为 pac-container 的位置
编辑2:
我正在尝试在地址更改和滚动时执行类似的操作,但即使这样也没有任何效果:
const top = this.indirizzo.nativeElement.getBoundingClientRect().top ;
const pacContainer = document.querySelector('.pac-container') as HTMLElement;
if (pacContainer) {
console.log(window.scrollY + top + 60);
pacContainer.style.top = window.scrollY + top + 60;
}
其中 indirizzo 是放置输入的 Div。
编辑 3:
.pac-container 是在下面生成的,<body>
所以我认为通过强制它在下面呈现<div class="indirizzo">
将解决问题......
编辑4:
通过将顶部设置为pac -container 到从屏幕顶部到输入底部的 X 像素的固定位置来解决,但仍在寻找更好的解决方案。
(所以从我输入的顶部 0 到末尾,我刚刚设置了 465px .pac-container top: 465px
)但是在某些屏幕上,高度可能会更低(一些移动设备 450 其他 460 其他 470)下拉菜单仍然绘制得很糟糕。
解决方案
如果您使用的是 Angular 材料,这将有所帮助
.pac-container {
z-index: 100000;
}
如果您使用的是 Bootstrap,这将对您有所帮助。
::ng-deep .pac-container {
z-index: 100000;
}
推荐阅读
- c# - C#用鼠标动态移动Picturebox类
- sql - 从显示的行中查询记录数
- node.js - 如何从 dynamoDB 的 LIST 中删除元素
- spring - Redis @Reference 在 Spring Data Redis 中不起作用
- rest - 如何使http请求中的搜索参数在jmeter中成为动态的
- cassandra-3.0 - 所有 I/O 线程上的所有连接都忙
- oracle - ora_12700的解决方案
- ios - 如何在导航栏后面显示图像?
- apache-kafka - kafka_2.11-0.9.0.1 与 Zookeeper 3.4.12 兼容吗?
- mysql - 多对多左连接,其中根据最小日期差异连接行