右键菜单优化
This commit is contained in:
@@ -76,11 +76,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="context-menu-native-hint" data-context-native-hint role="note" aria-label="Ctrl 右键提示">
|
||||||
|
<kbd>Ctrl</kbd> + 右键:浏览器原生菜单
|
||||||
|
</div>
|
||||||
|
|
||||||
<script is:inline>
|
<script is:inline>
|
||||||
(() => {
|
(() => {
|
||||||
const menu = document.querySelector('[data-context-menu]');
|
const menu = document.querySelector('[data-context-menu]');
|
||||||
if (!menu) return;
|
if (!menu) return;
|
||||||
|
|
||||||
|
const nativeHint = document.querySelector('[data-context-native-hint]');
|
||||||
const selectionItems = [...menu.querySelectorAll('[data-selection-item]')];
|
const selectionItems = [...menu.querySelectorAll('[data-selection-item]')];
|
||||||
const selectionGroup = menu.querySelector('[data-selection-group]');
|
const selectionGroup = menu.querySelector('[data-selection-group]');
|
||||||
const commentsItems = [...menu.querySelectorAll('[data-comments-item]')];
|
const commentsItems = [...menu.querySelectorAll('[data-comments-item]')];
|
||||||
@@ -88,6 +93,7 @@
|
|||||||
const focusableSelector = 'a[href], button:not([disabled])';
|
const focusableSelector = 'a[href], button:not([disabled])';
|
||||||
let lastSelectionText = '';
|
let lastSelectionText = '';
|
||||||
let lastImage = null;
|
let lastImage = null;
|
||||||
|
let nativeHintTimer = 0;
|
||||||
|
|
||||||
const isNativeContextTarget = (target) =>
|
const isNativeContextTarget = (target) =>
|
||||||
target instanceof Element &&
|
target instanceof Element &&
|
||||||
@@ -162,6 +168,15 @@
|
|||||||
menu.style.top = `${top}px`;
|
menu.style.top = `${top}px`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showNativeHint = () => {
|
||||||
|
if (!nativeHint) return;
|
||||||
|
window.clearTimeout(nativeHintTimer);
|
||||||
|
nativeHint.classList.add('is-visible');
|
||||||
|
nativeHintTimer = window.setTimeout(() => {
|
||||||
|
nativeHint.classList.remove('is-visible');
|
||||||
|
}, 2600);
|
||||||
|
};
|
||||||
|
|
||||||
const jumpToComments = () => {
|
const jumpToComments = () => {
|
||||||
const target = getCommentsTarget();
|
const target = getCommentsTarget();
|
||||||
target?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
target?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||||
@@ -216,12 +231,19 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener('contextmenu', (event) => {
|
document.addEventListener('contextmenu', (event) => {
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
closeMenu();
|
||||||
|
nativeHint?.classList.remove('is-visible');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isNativeContextTarget(event.target)) return;
|
if (isNativeContextTarget(event.target)) return;
|
||||||
|
|
||||||
lastSelectionText = getSelectionText();
|
lastSelectionText = getSelectionText();
|
||||||
lastImage = getImageTarget(event.target);
|
lastImage = getImageTarget(event.target);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
openMenu(event.clientX, event.clientY);
|
openMenu(event.clientX, event.clientY);
|
||||||
|
showNativeHint();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('click', (event) => {
|
document.addEventListener('click', (event) => {
|
||||||
|
|||||||
@@ -377,6 +377,53 @@ a {
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.context-menu-native-hint {
|
||||||
|
position: fixed;
|
||||||
|
right: max(16px, env(safe-area-inset-right));
|
||||||
|
bottom: max(16px, env(safe-area-inset-bottom));
|
||||||
|
z-index: 900;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
max-width: min(300px, calc(100vw - 32px));
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.58);
|
||||||
|
border-radius: 999px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
color: #4f565b;
|
||||||
|
font-size: 0.84rem;
|
||||||
|
font-weight: 650;
|
||||||
|
line-height: 1.3;
|
||||||
|
background:
|
||||||
|
linear-gradient(145deg, rgba(255, 255, 255, 0.78), rgba(235, 248, 231, 0.68)),
|
||||||
|
rgba(245, 252, 241, 0.82);
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.86),
|
||||||
|
0 12px 30px rgba(44, 55, 63, 0.14);
|
||||||
|
backdrop-filter: blur(16px) saturate(165%);
|
||||||
|
-webkit-backdrop-filter: blur(16px) saturate(165%);
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
transform: translate3d(0, 8px, 0);
|
||||||
|
transition:
|
||||||
|
opacity 0.18s ease,
|
||||||
|
transform 0.18s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-native-hint.is-visible {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translate3d(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-native-hint kbd {
|
||||||
|
border: 1px solid rgba(178, 194, 170, 0.52);
|
||||||
|
border-radius: 7px;
|
||||||
|
padding: 1px 6px;
|
||||||
|
color: var(--accent);
|
||||||
|
font: inherit;
|
||||||
|
background: rgba(255, 255, 255, 0.52);
|
||||||
|
box-shadow: inset 0 -1px 0 rgba(44, 55, 63, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
.nav-links a:hover,
|
.nav-links a:hover,
|
||||||
.nav-random:hover,
|
.nav-random:hover,
|
||||||
.nav-search:hover,
|
.nav-search:hover,
|
||||||
@@ -858,6 +905,24 @@ a {
|
|||||||
color: #c1cdd2;
|
color: #c1cdd2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:root[data-theme='dark'] .context-menu-native-hint {
|
||||||
|
border-color: rgba(166, 184, 194, 0.2);
|
||||||
|
color: #e2ecef;
|
||||||
|
background:
|
||||||
|
linear-gradient(145deg, rgba(27, 39, 47, 0.9), rgba(10, 17, 22, 0.82)),
|
||||||
|
rgba(14, 22, 28, 0.84);
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
0 12px 30px rgba(0, 0, 0, 0.32);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[data-theme='dark'] .context-menu-native-hint kbd {
|
||||||
|
border-color: rgba(166, 184, 194, 0.2);
|
||||||
|
color: var(--accent);
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
.hero {
|
.hero {
|
||||||
width: min(var(--wide-width), calc(100% - (var(--page-gutter) * 2)));
|
width: min(var(--wide-width), calc(100% - (var(--page-gutter) * 2)));
|
||||||
min-height: 360px;
|
min-height: 360px;
|
||||||
|
|||||||
Reference in New Issue
Block a user