html如何自动扩展,html – 使用algolia自动完成功能创建可扩展材质搜索栏

2022-06-02 00:00:00 这是 下拉 我在 菜单 我不

我在我的应用程序中使用algolia autocomplete.我想构建一个像page这样的可扩展示例扩展的搜索栏.我有一个带有标题栏的布局,其中有一个用于更大屏幕的搜索输入.在小屏幕上我只有一个放大镜图标,点击切换另一个带有搜索栏的标题,我初隐藏它.这是fiddle,我无法工作,但希望它仍然可以给你一些概述.这是布局:

我遇到的问题是,由于某种原因,在小屏幕上看不到下拉菜单,而是在更大的屏幕上.这是scss / css:

.algolia-autocomplete {

display: flex!important;

flex: auto!important;

height: ;

}

.aa-dropdown-menu {

position: relative;

top: -6px;

border-radius: 3px;

margin: 6px 0 0;

padding: 0;

text-align: left;

height: auto;

position: relative;

background: $white;

border: 1px solid #ccc;

width: ;

left: 0 !important;

box-shadow: 0 1px 0 0 rgba(0,0.2),0 2px 3px 0 rgba(0,0.1);

}

.aa-dropdown-menu .aa-suggestions {

position: relative;

z-index: 1000;

}

.aa-dropdown-menu [class^="aa-dataset-"] {

position: relative;

border: 0;

border-radius: 3px;

overflow: auto;

padding: 0;

color: #3c3e42;

font-weight: 500;

}

.aa-dropdown-menu * {

box-sizing: border-box;

}

.aa-suggestion {

display: block;

width: ;

height: 72px;

clear: both;

.mdc-list-item {

height: 72px;

}

}

.aa-suggestion span {

white-space: nowrap !important;

text-overflow: ellipsis;

overflow: hidden;

display: block;

float: left;

line-height: 1em;

width: calc( - 30px);

}

.aa-suggestion.aa-cursor {

background-color: transparent;

}

.aa-suggestion em {

color: #00bcd4;

font-weight: 700;

}

.aa-suggestion img {

float: left;

height: 44px;

width: 44px;

margin-right: 6px;

}

.aa-suggestion a {

color: #3c3e42;

}

.aa-suggestions-category {

font-weight: 700;

color: #3c3e42;

border-bottom: 1px solid rgba(102,105,0.17);

}

.powered-by-algolia {

padding-left: 15px;

border-top: 1px solid rgba(102,0.17);

display: flex;

align-items: center;

height: 30px;

}

.aa-input-container {

display: inline-block;

position: relative; }

.aa-input-search {

width: ;

height: 30px;

padding: 12px 28px 12px 12px;

box-sizing: border-box;

-webkit-appearance: none;

-moz-appearance: none;

appearance: none; }

.aa-input-search::-webkit-search-decoration,.aa-input-search::-webkit-search-cancel-button,.aa-input-search::-webkit-search-results-button,.aa-input-search::-webkit-search-results-decoration {

display: none;

}

.media {

margin: 10px 0;

}

.media-body {

p {

margin: 0;

}

}

.toolbar--custom {

color: $white;

.mdc-toolbar__row {

min-height: 56px;

}

form,.autocomplete-search-field {

width: ;

}

.mdc-text-field--box:not(.mdc-text-field--upgraded) {

height: 36px;

}

.mdc-text-field--box {

overflow: visible;

margin: auto;

.mdc-text-field__icon {

bottom: 8px;

font-size: 22px;

}

}

.mdc-text-field--box:after,.mdc-text-field--box:before {

top: 0;

left: 0;

width: ;

height: ;

}

#search-input-open {

display: none;

}

@media only screen and (max-width: 782px) {

#search-input-open {

display: block;

}

.search-field-desktop {

display: none;

}

}

}

.search-field-phone {

clip-path: circle(0%);

visibility: hidden;

.mdc-text-field {

clip-path: circle(0%);

}

}

@mixin search-animated-open {

-webkit-animation: open 0.3s forwards;

animation: open 0.3s forwards;

animation-timing-function: $mdc-animation-standard-curve-timing-function;

}

@mixin search-animated-close {

-webkit-animation: close 0.3s forwards;

animation: close 0.3s forwards;

animation-timing-function: $mdc-animation-standard-curve-timing-function;

}

.search-field-phone-open,{

visibility: visible;

@include search-animated-open;

.mdc-text-field {

@include search-animated-open;

}

}

.search-field-phone-close,{

@include search-animated-close;

.mdc-text-field {

@include search-animated-close;

}

}

@keyframes open {

from {

clip-path: circle(0 at calc( - 68px) 50%);

}

to {

clip-path: circle(150% at calc( - 68px) 50%);

}

}

@keyframes close {

from {

clip-path: circle(150% at calc( - 68px) 50%);

}

to {

clip-path: circle(0 at calc( - 68px) 50%);

visibility: hidden;

}

}

整个页面的布局如下所示:

导航部分是上面显示的标题文件.这是侧边栏的部分:

这是页面的css:

body {

margin: 0;

}

#app {

display: flex;

}

.page-content {

display: inline-flex;

flex-direction: column;

flex-grow: 1;

height: ;

box-sizing: border-box;

}

我不确定导致这种行为的原因是什么,为什么大屏幕的下拉菜单可见,而较小屏幕的下拉菜单不可用?

更新

我注意到当我在小屏幕上打开搜索输入时,如果我删除了search-field-phone-open,那么下拉菜单是可见的,我不确定该类中的是什么导致下拉列表不可见?

.search-field-phone-open,{

visibility: visible;

@include search-animated-open;

.mdc-text-field {

@include search-animated-open;

}

}

佳答案

我不确定我理解你需要什么,但请查看下面的代码:

var client = algoliasearch('latency','6be0576ff61c053d5f9a3225e2a90f76');

var index = client.initIndex('contacts');

$('.input-search').autocomplete({ hint: false },[

{

source: function(searchBar,cb) {

index.search(searchBar,{ hitsPerPage: 5 },function(error,content) {

if (error) {

cb([]);

return;

}

cb(content.hits,content);

});

},displayKey: 'name',templates: {

suggestion: function(suggestion) {

return suggestion._highlightResult.name.value;

}

}

}

]);

.algolia-autocomplete {

display: flex!important;

flex: auto!important;

height: ;

}

.aa-dropdown-menu {

position: relative;

top: -6px;

border-radius: 3px;

margin: 6px 0 0;

padding: 0;

text-align: left;

height: auto;

position: relative;

background: $white;

border: 1px solid #ccc;

width: ;

left: 0 !important;

box-shadow: 0 1px 0 0 rgba(0,0.1);

}

.aa-dropdown-menu:before {

position: absolute;

content: '';

width: 14px;

height: 14px;

background: #fff;

z-index: 0;

top: -7px;

border-top: 1px solid #D9D9D9;

border-right: 1px solid #D9D9D9;

transform: rotate(-45deg);

border-radius: 2px;

z-index: 999;

display: block;

left: 24px;

}

.aa-dropdown-menu .aa-suggestions {

position: relative;

z-index: 1000;

}

.aa-dropdown-menu [class^="aa-dataset-"] {

position: relative;

border: 0;

border-radius: 3px;

overflow: auto;

padding: 8px 8px 8px;

color: #3c3e42;

font-weight: 500;

}

.aa-dropdown-menu * {

box-sizing: border-box;

}

.aa-suggestion {

padding: 0 4px 0;

display: block;

width: ;

height: 38px;

clear: both;

}

.aa-suggestion span {

white-space: nowrap !important;

text-overflow: ellipsis;

overflow: hidden;

display: block;

float: left;

line-height: 1em;

width: calc( - 30px);

}

.aa-suggestion.aa-cursor {

background-color: transparent;

}

.aa-suggestion em {

color: #00bcd4;

font-weight: 700;

}

.aa-suggestion img {

float: left;

height: 44px;

width: 44px;

margin-right: 6px;

}

.aa-suggestion a {

color: #3c3e42;

}

.aa-suggestions-category {

font-weight: 700;

color: #3c3e42;

border-bottom: 1px solid rgba(102,0.17);

}

.mdl-textfield {

margin: -20px !important;

}

/* fallback */

@font-face {

font-family: 'Material Icons';

font-style: normal;

font-weight: 400;

src: url(https://fonts.gstatic.com/s/materialicons/v36/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2');

}

.material-icons {

font-family: 'Material Icons';

font-weight: normal;

font-style: normal;

font-size: 24px;

line-height: 1;

letter-spacing: normal;

text-transform: none;

display: inline-block;

white-space: nowrap;

word-wrap: normal;

direction: ltr;

-moz-font-feature-settings: 'liga';

-moz-osx-font-smoothing: grayscale;

}

希望这对你有所帮助.

参考

我在GitHub上提到了mdc-toolbar.

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

相关文章