perf(local-search): optimize local search popup

This commit is contained in:
XPoet 2022-09-29 10:09:53 +08:00
parent e65ec7f711
commit e1890116b2
3 changed files with 95 additions and 97 deletions

View File

@ -14,7 +14,7 @@
class="search-input" class="search-input"
> >
</div> </div>
<span class="popup-btn-close"> <span class="close-popup-btn">
<i class="fas fa-times"></i> <i class="fas fa-times"></i>
</span> </span>
</div> </div>

View File

@ -1,97 +1,93 @@
$icon-size = 1.2rem; $icon-size = 1.2rem
$search-header-height = 3rem
.search-pop-overlay { .search-pop-overlay {
position: fixed; position fixed
display: flex; display flex
height: 100%; height 100%
width: 100%; width 100%
left: 0; left 0
top: 0; top 0
background: rgba(0, 0, 0, 0); background rgba(0, 0, 0, 0)
visibility: hidden; visibility hidden
z-index: $z-index-8; z-index $z-index-8
transition-t("visibility, background", "0, 0", "0.3, 0.3", "ease, ease"); transition-t("visibility, background", "0, 0", "0.3, 0.3", "ease, ease")
&.active { &.active {
visibility: visible; visibility visible
background: rgba(0, 0, 0, 0.35); background rgba(0, 0, 0, 0.35)
.search-popup { .search-popup {
transform: scale(1); transform scale(1)
} }
} }
.search-popup { .search-popup {
background: var(--background-color); background var(--background-color)
border-radius: 5px; border-radius 0.4rem
height: 80%; height 80%
width: 70%; width 70%
margin: auto; margin auto
transform: scale(0); transform scale(0)
z-index: $z-index-6; z-index $z-index-6
transition-t("transform", "0", "0.3", "ease"); transition-t("transform", "0", "0.3", "ease")
+keep-tablet() { +keep-tablet() {
width: 80%; width 80%
} }
+keep-mobile() { +keep-mobile() {
width: 90%; width 90%
} }
.search-header { .search-header {
background: var(--fourth-text-color); background var(--fourth-text-color)
border-top-left-radius: 2px; border-top-left-radius 0.2rem
border-top-right-radius: 2px; border-top-right-radius 0.2rem
display: flex; display flex
padding: 10px; height $search-header-height
align-items center
.search-input-field-pre, .popup-btn-close { padding 0 1rem
font-size: $icon-size;
padding: 0 10px;
display: flex;
align-items: center;
}
.search-input-field-pre { .search-input-field-pre {
cursor: pointer; cursor pointer
color: var(--third-text-color); color var(--default-text-color)
margin-right 0.2rem
} }
.popup-btn-close {
color: var(--default-text-color);
}
.search-input-container { .search-input-container {
flex-grow 1
flex-grow: 1; padding 0.2rem
padding: 2px;
.search-input { .search-input {
background: transparent; background transparent
border: 0; border 0
outline: 0; outline 0
width: 100%; width 100%
font-size: 1.2rem; font-size 1.2rem
color: var(--default-text-color); color var(--default-text-color)
&::-webkit-search-cancel-button { &::-webkit-search-cancel-button {
display: none; display none
}
&::-webkit-input-placeholder {
color var(--third-text-color)
font-size 1rem
} }
} }
} }
.popup-btn-close { .close-popup-btn {
cursor: pointer; color var(--default-text-color)
font-size $icon-size
cursor pointer
&:hover .fas, far, fab { &:hover .fas, far, fab {
color: var(--first-text-color); color var(--first-text-color)
} }
} }
@ -99,66 +95,68 @@ $icon-size = 1.2rem;
#search-result { #search-result {
display: flex; position relative
height: calc(100% - 55px); box-sizing border-box
overflow: auto; display flex
padding: 5px 25px; height 'calc(100% - %s)' % $search-header-height
overflow auto
padding 0.3rem 1.5rem
.search-result-list { .search-result-list {
width: 100%; width 100%
height: 100%; height 100%
font-size: 1rem; font-size 1rem
li { li {
border-bottom: 1px dashed var(--border-color); box-sizing border-box
padding: 10px 0; border-bottom 0.1rem dashed var(--border-color)
margin: 10px 0; padding 0.8rem 0
box-sizing: border-box; margin 0.8rem 0
&:last-child { &:last-child {
border-bottom: none; border-bottom none
} }
.search-result-title { .search-result-title {
position: relative; position relative
font-weight: bold; font-weight bold
margin-bottom: 10px; margin-bottom 0.8rem
padding-left: 16px; padding-left 1rem
display: flex; display flex
align-items: center; align-items center
&::after { &::after {
content: ''; content ''
position: absolute; position absolute
width: 5px; width 0.4rem
height: 5px; height 0.4rem
border-radius: 50%; border-radius 50%
top: 50%; top 50%
transform: translateY(-50%); transform translateY(-50%)
left: 0; left 0
background: var(--default-text-color); background var(--default-text-color)
} }
} }
.search-result { .search-result {
line-height: 2rem; line-height 2rem
margin: 0; margin 0
padding-left: 16px; padding-left 1rem
word-wrap: break-word; word-wrap break-word
} }
a { a {
&:hover { &:hover {
color: var(--default-text-color); color var(--default-text-color)
} }
} }
.search-keyword { .search-keyword {
border-bottom: 1px dashed var(--primary-color); border-bottom 0.1rem dashed var(--primary-color)
color: var(--primary-color); color var(--primary-color)
font-weight: bold; font-weight bold
} }
} }
@ -166,8 +164,8 @@ $icon-size = 1.2rem;
#no-result { #no-result {
color: var(--third-text-color); color var(--third-text-color)
margin: auto; margin auto
} }
} }

View File

@ -271,7 +271,7 @@ KEEP.initLocalSearch = () => {
searchInputDom.focus(); searchInputDom.focus();
inputEventFunction(); inputEventFunction();
}); });
document.querySelector('.popup-btn-close').addEventListener('click', onPopupClose); document.querySelector('.close-popup-btn').addEventListener('click', onPopupClose);
window.addEventListener('pjax:success', onPopupClose); window.addEventListener('pjax:success', onPopupClose);
window.addEventListener('keyup', event => { window.addEventListener('keyup', event => {
if (event.key === 'Escape') { if (event.key === 'Escape') {