feat: 添加微信JS-SDK文件并删除无用HTML文件
删除多个测试用的HTML文件,包括键盘辅助栏和可编辑区域相关示例 添加微信JS-SDK文件jweixin-1.6.0.js 更新CSS样式,增加模态框和标题框底部计数功能
This commit is contained in:
159
2.html
159
2.html
@@ -1,159 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>可点击其他元素+保持光标不丢</title>
|
||||
<style>
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 50px auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
/* 可编辑区域 */
|
||||
.edit-area {
|
||||
min-height: 100px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
outline: none;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* 其他可点击元素(都能正常触发点击逻辑) */
|
||||
.other-btn {
|
||||
margin: 0 8px 10px 0;
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background: #4285f4;
|
||||
color: white;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.link {
|
||||
color: #4285f4;
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
margin-right: 15px;
|
||||
}
|
||||
.popup-box {
|
||||
margin: 15px 0;
|
||||
padding: 15px;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 8px;
|
||||
background: #f9f9f9;
|
||||
cursor: pointer;
|
||||
}
|
||||
#popup {
|
||||
display: none;
|
||||
margin: 10px 0;
|
||||
padding: 10px;
|
||||
border: 1px solid #ff4444;
|
||||
background: #fff0f0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<!-- 核心:可编辑区域 -->
|
||||
<div class="edit-area" contenteditable="true" id="editArea">
|
||||
点击这里输入...点击下方按钮/链接/区域,它们能正常工作,光标也不会消失
|
||||
</div>
|
||||
|
||||
<!-- 其他可点击元素(都能正常触发逻辑) -->
|
||||
<button class="other-btn" id="logBtn">点击打印日志</button>
|
||||
<button class="other-btn" id="insertBtn">点击插入文本到编辑区</button>
|
||||
<div class="link" id="jumpLink">点击模拟跳转(不会真跳)</div>
|
||||
<div class="popup-box" id="showPopupBtn">点击显示弹窗</div>
|
||||
<div id="popup">这是弹窗内容(点击其他地方不会关闭,除非加逻辑)</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 1. 获取核心元素
|
||||
const editArea = document.getElementById('editArea');
|
||||
const popup = document.getElementById('popup');
|
||||
let lastRange = null; // 存储光标位置,用于恢复
|
||||
|
||||
// 2. 初始化:自动聚焦+光标定位到末尾
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
editArea.focus();
|
||||
moveCursorToEnd(editArea);
|
||||
});
|
||||
|
||||
// 3. 关键:监听可编辑区域的blur事件(即将失焦时)
|
||||
editArea.addEventListener('blur', () => {
|
||||
// 延迟10ms重新聚焦(让其他元素的点击逻辑先执行,避免冲突)
|
||||
setTimeout(() => {
|
||||
if (lastRange) { // 恢复之前的光标位置
|
||||
editArea.focus();
|
||||
const selection = window.getSelection();
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(lastRange);
|
||||
}
|
||||
}, 10);
|
||||
});
|
||||
|
||||
// 4. 实时保存光标位置(确保失焦后能恢复)
|
||||
editArea.addEventListener('selectionchange', () => {
|
||||
const selection = window.getSelection();
|
||||
if (selection.rangeCount > 0) {
|
||||
// 克隆光标范围(避免原对象被覆盖)
|
||||
lastRange = selection.getRangeAt(0).cloneRange();
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------- 以下是其他元素的正常点击逻辑(可自定义) ----------------------
|
||||
// 按钮1:打印日志(正常触发)
|
||||
document.getElementById('logBtn').addEventListener('click', () => {
|
||||
console.log('按钮被点击了!当前编辑区内容:', editArea.innerText);
|
||||
alert('按钮点击成功!光标还在编辑区哦~');
|
||||
});
|
||||
|
||||
// 按钮2:插入文本到编辑区(正常触发+光标同步)
|
||||
document.getElementById('insertBtn').addEventListener('click', () => {
|
||||
const insertText = '【插入的文本】';
|
||||
const selection = window.getSelection();
|
||||
const range = selection.getRangeAt(0);
|
||||
|
||||
// 插入文本(不影响原光标位置)
|
||||
range.deleteContents();
|
||||
const textNode = document.createTextNode(insertText);
|
||||
range.insertNode(textNode);
|
||||
|
||||
// 光标移到插入文本末尾
|
||||
range.setStartAfter(textNode);
|
||||
range.setEndAfter(textNode);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
|
||||
// 确保编辑区仍有焦点(双重保险)
|
||||
editArea.focus();
|
||||
});
|
||||
|
||||
// 链接:模拟跳转(正常触发,不真跳转)
|
||||
document.getElementById('jumpLink').addEventListener('click', () => {
|
||||
alert('模拟跳转逻辑触发!(实际不会跳转,光标还在编辑区)');
|
||||
});
|
||||
|
||||
// 区域:显示弹窗(正常触发)
|
||||
document.getElementById('showPopupBtn').addEventListener('click', () => {
|
||||
popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
|
||||
});
|
||||
|
||||
// ---------------------- 辅助函数 ----------------------
|
||||
// 光标定位到编辑区末尾
|
||||
function moveCursorToEnd(element) {
|
||||
const range = document.createRange();
|
||||
const selection = window.getSelection();
|
||||
range.selectNodeContents(element);
|
||||
range.collapse(false); // false=末尾,true=开头
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,234 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||
<title>Contenteditable 键盘辅助栏</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
padding: 20px;
|
||||
padding-bottom: 60px; /* 预留辅助栏空间 */
|
||||
background-color: #f5f5f7;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
h3 {
|
||||
color: #1d1d1f;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.editable-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
[contenteditable="true"] {
|
||||
width: 100%;
|
||||
min-height: 50px;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 12px;
|
||||
font-size: 16px;
|
||||
background-color: white;
|
||||
transition: border-color 0.2s;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
[contenteditable="true"]:focus {
|
||||
border-color: #007aff;
|
||||
box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
|
||||
}
|
||||
|
||||
[contenteditable="true"]:empty:before {
|
||||
content: attr(data-placeholder);
|
||||
color: #999;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* 键盘辅助栏样式 */
|
||||
.keyboard-accessory {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 55px;
|
||||
background-color: white;
|
||||
border-top: 1px solid #eee;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 16px;
|
||||
transition: transform 0.3s ease;
|
||||
transform: translateY(100%); /* 默认隐藏 */
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.keyboard-accessory.show {
|
||||
transform: translateY(0); /* 显示时移回底部 */
|
||||
}
|
||||
|
||||
.accessory-btn {
|
||||
padding: 8px 20px;
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.accessory-btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
color: #666;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
color: #333;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.confirm-btn {
|
||||
color: white;
|
||||
background-color: #007aff;
|
||||
}
|
||||
|
||||
/* 深色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body {
|
||||
background-color: #1c1c1e;
|
||||
}
|
||||
|
||||
h3 {
|
||||
color: #f5f5f7;
|
||||
}
|
||||
|
||||
[contenteditable="true"] {
|
||||
background-color: #2c2c2e;
|
||||
border-color: #3a3a3c;
|
||||
color: white;
|
||||
}
|
||||
|
||||
[contenteditable="true"]:empty:before {
|
||||
color: #8e8e93;
|
||||
}
|
||||
|
||||
.keyboard-accessory {
|
||||
background-color: #1c1c1e;
|
||||
border-top-color: #3a3a3c;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
color: #d1d1d6;
|
||||
background-color: #2c2c2e;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
color: #d1d1d6;
|
||||
background-color: #3a3a3c;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h3>Contenteditable 键盘辅助栏</h3>
|
||||
|
||||
<div class="editable-group">
|
||||
<div contenteditable="true" id="mainEditable" data-placeholder="点击输入内容..."></div>
|
||||
</div>
|
||||
|
||||
<div class="editable-group">
|
||||
<div contenteditable="true" data-placeholder="另一个可编辑区域..."></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 键盘辅助栏 -->
|
||||
<div class="keyboard-accessory" id="keyboardAccessory">
|
||||
<button class="accessory-btn cancel-btn" id="cancelBtn">取消</button>
|
||||
<button class="accessory-btn clear-btn" id="clearBtn">清除</button>
|
||||
<button class="accessory-btn confirm-btn" id="confirmBtn">完成</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 获取DOM元素
|
||||
const editables = document.querySelectorAll('[contenteditable="true"]');
|
||||
const keyboardAccessory = document.getElementById("keyboardAccessory");
|
||||
const cancelBtn = document.getElementById("cancelBtn");
|
||||
const clearBtn = document.getElementById("clearBtn");
|
||||
const confirmBtn = document.getElementById("confirmBtn");
|
||||
let activeEditable = null; // 当前聚焦的可编辑元素
|
||||
|
||||
// 可编辑元素聚焦事件:显示辅助栏
|
||||
editables.forEach((editable) => {
|
||||
console.log("editable", editable);
|
||||
|
||||
editable.addEventListener("focus", (e) => {
|
||||
activeEditable = e.target;
|
||||
keyboardAccessory.classList.add("show");
|
||||
});
|
||||
|
||||
editable.addEventListener("blur", () => {
|
||||
// 延迟隐藏,确保按钮点击事件能触发
|
||||
setTimeout(() => {
|
||||
// 检查是否还有其他可编辑元素处于聚焦状态
|
||||
const hasActive = Array.from(editables).some((el) => document.activeElement === el);
|
||||
if (!hasActive) {
|
||||
keyboardAccessory.classList.remove("show");
|
||||
activeEditable = null;
|
||||
}
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
|
||||
// 取消按钮:取消聚焦(收起键盘)
|
||||
cancelBtn.addEventListener("click", () => {
|
||||
if (activeEditable) {
|
||||
activeEditable.blur();
|
||||
}
|
||||
});
|
||||
|
||||
// 清除按钮:清空当前可编辑元素内容
|
||||
clearBtn.addEventListener("click", () => {
|
||||
if (activeEditable) {
|
||||
activeEditable.textContent = "";
|
||||
activeEditable.focus(); // 保持聚焦状态
|
||||
}
|
||||
});
|
||||
|
||||
// 完成按钮:获取内容并取消聚焦
|
||||
confirmBtn.addEventListener("click", () => {
|
||||
if (activeEditable) {
|
||||
const value = activeEditable.textContent.trim();
|
||||
if (value) {
|
||||
alert(`输入内容:${value}`);
|
||||
} else {
|
||||
alert("内容为空");
|
||||
}
|
||||
activeEditable.blur();
|
||||
}
|
||||
});
|
||||
|
||||
// 监听窗口大小变化,确保辅助栏位置正确
|
||||
window.addEventListener("resize", () => {
|
||||
if (activeEditable) {
|
||||
keyboardAccessory.classList.add("show");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -53,11 +53,12 @@ editor {
|
||||
}
|
||||
.container .title-box {
|
||||
width: 9.4rem;
|
||||
margin: 0 auto 0.4rem;
|
||||
margin: 0 auto 0.6rem;
|
||||
background-color: #ffffff;
|
||||
border: 0.0133rem solid #f2f2f2;
|
||||
border-radius: 0.4rem;
|
||||
padding: 0.4rem;
|
||||
padding: 0.4rem 0.4rem 0.6rem;
|
||||
position: relative;
|
||||
}
|
||||
.container .title-box .input {
|
||||
width: 100%;
|
||||
@@ -72,6 +73,13 @@ editor {
|
||||
.container .title-box .input::placeholder {
|
||||
color: #757575;
|
||||
}
|
||||
.container .title-box .sum {
|
||||
position: absolute;
|
||||
right: 0.4rem;
|
||||
bottom: 0.1rem;
|
||||
color: #555555;
|
||||
font-size: 14px;
|
||||
}
|
||||
.container .editor-box {
|
||||
width: 9.4rem;
|
||||
margin: 0 auto 0.4rem;
|
||||
@@ -330,6 +338,79 @@ editor {
|
||||
width: 100%;
|
||||
height: 2.2667rem;
|
||||
}
|
||||
.container .model-container {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.container .model-container .model-main {
|
||||
position: relative;
|
||||
z-index: 9;
|
||||
width: 80%;
|
||||
background-color: #ffffff;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
text-align: center;
|
||||
}
|
||||
.container .model-container .model-main .model-title {
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
width: 100%;
|
||||
padding: 18px;
|
||||
font-weight: bold;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.container .model-container .model-main .model-content {
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
padding: 10px;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
.container .model-container .model-main .model-buttons {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.container .model-container .model-main .model-buttons .button {
|
||||
flex: 1;
|
||||
padding: 18px 10px;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
font-size: 16px;
|
||||
outline: none;
|
||||
background-color: #ffffff;
|
||||
border-top: 1px solid #f2f2f2;
|
||||
border-right: 1px solid #f2f2f2;
|
||||
}
|
||||
.container .model-container .model-main .model-buttons .button.confirm {
|
||||
color: var(--theme);
|
||||
font-weight: bold;
|
||||
}
|
||||
.container .model-container .model-main .model-buttons .button:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
.container .model-container .model-main .model-buttons .button:active {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
.container .model-container .model-mask {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
background-color: rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
.btn-f {
|
||||
position: fixed;
|
||||
top: 50px;
|
||||
|
||||
@@ -64,11 +64,12 @@ editor {
|
||||
|
||||
.title-box {
|
||||
width: 9.4rem;
|
||||
margin: 0 auto 0.4rem;
|
||||
background-color: rgba(255, 255, 255, 1);
|
||||
border: 0.0133rem solid rgba(242, 242, 242, 1);
|
||||
margin: 0 auto 0.6rem;
|
||||
background-color: #ffffff;
|
||||
border: 0.0133rem solid #f2f2f2;
|
||||
border-radius: 0.4rem;
|
||||
padding: 0.4rem;
|
||||
padding: 0.4rem 0.4rem 0.6rem;
|
||||
position: relative;
|
||||
|
||||
.input {
|
||||
width: 100%;
|
||||
@@ -83,6 +84,14 @@ editor {
|
||||
color: rgba(117, 117, 117, 1);
|
||||
}
|
||||
}
|
||||
|
||||
.sum {
|
||||
position: absolute;
|
||||
right: 0.4rem;
|
||||
bottom: 0.1rem;
|
||||
color: rgb(85, 85, 85);
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.editor-box {
|
||||
@@ -388,6 +397,80 @@ editor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.model-container {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
.model-main {
|
||||
position: relative;
|
||||
z-index: 9;
|
||||
width: 80%;
|
||||
background-color: #ffffff;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
text-align: center;
|
||||
.model-title {
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
width: 100%;
|
||||
padding: 18px;
|
||||
font-weight: bold;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.model-content {
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
padding: 10px;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
.model-buttons {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
.button {
|
||||
flex: 1;
|
||||
padding: 18px 10px;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
font-size: 16px;
|
||||
outline: none;
|
||||
background-color: #ffffff;
|
||||
border-top: 1px solid #f2f2f2;
|
||||
border-right: 1px solid #f2f2f2;
|
||||
&.confirm {
|
||||
color: var(--theme);
|
||||
font-weight: bold;
|
||||
}
|
||||
&:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
&:active {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.model-mask {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
background-color: rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-f {
|
||||
|
||||
@@ -1,265 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
||||
<title>固定定位的键盘辅助栏</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
padding: 20px;
|
||||
padding-bottom: 60px; /* 预留辅助栏空间 */
|
||||
background-color: #f5f5f7;
|
||||
/* 关键:移除可能影响fixed定位的属性 */
|
||||
transform: none !important;
|
||||
perspective: none !important;
|
||||
}
|
||||
|
||||
/* 长内容区域,用于测试滑动 */
|
||||
.long-content {
|
||||
height: 2000px; /* 足够长以触发滚动 */
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
h3 {
|
||||
color: #1d1d1f;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 12px;
|
||||
font-size: 16px;
|
||||
background-color: white;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.input-field:focus {
|
||||
outline: none;
|
||||
border-color: #007aff;
|
||||
box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
|
||||
}
|
||||
|
||||
/* 键盘辅助栏核心样式(固定定位优化) */
|
||||
.keyboard-accessory {
|
||||
position: fixed; /* 固定在视口,不随滚动变化 */
|
||||
left: 0;
|
||||
right: 0; /* 替代width:100%,避免滚动条问题 */
|
||||
height: 55px;
|
||||
background-color: white;
|
||||
border-top: 1px solid #eee;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 16px;
|
||||
transition: transform 0.3s ease, bottom 0.3s ease;
|
||||
transform: translateY(100%); /* 默认隐藏 */
|
||||
z-index: 9999; /* 确保在所有内容之上 */
|
||||
/* 关键:消除滚动时的抖动 */
|
||||
will-change: transform, bottom;
|
||||
backface-visibility: hidden;
|
||||
}
|
||||
|
||||
.keyboard-accessory.show {
|
||||
transform: translateY(0); /* 显示时移出隐藏状态 */
|
||||
}
|
||||
|
||||
.accessory-btn {
|
||||
padding: 8px 20px;
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
color: #666;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
color: #333;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.confirm-btn {
|
||||
color: white;
|
||||
background-color: #007aff;
|
||||
}
|
||||
|
||||
/* 深色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body { background-color: #1c1c1e; }
|
||||
h3 { color: #f5f5f7; }
|
||||
.input-field {
|
||||
background-color: #2c2c2e;
|
||||
border-color: #3a3a3c;
|
||||
color: white;
|
||||
}
|
||||
.keyboard-accessory {
|
||||
background-color: #1c1c1e;
|
||||
border-top-color: #3a3a3c;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h3>固定定位的键盘辅助栏</h3>
|
||||
<div class="input-group">
|
||||
<input
|
||||
type="text"
|
||||
class="input-field"
|
||||
placeholder="点击输入,辅助栏不随滑动移动..."
|
||||
>
|
||||
</div>
|
||||
|
||||
<!-- 长内容区域,用于测试滑动效果 -->
|
||||
<div class="long-content">
|
||||
<p>滚动页面测试辅助栏是否固定...</p>
|
||||
<p style="margin-top: 500px;">中间位置...</p>
|
||||
<p style="margin-top: 1000px;">底部位置...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 键盘辅助栏 -->
|
||||
<div class="keyboard-accessory" id="keyboardAccessory">
|
||||
<button class="accessory-btn cancel-btn" id="cancelBtn">取消</button>
|
||||
<button class="accessory-btn clear-btn" id="clearBtn">清52除</button>
|
||||
<button class="accessory-btn confirm-btn" id="confirmBtn">完成</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 获取元素
|
||||
const inputs = document.querySelectorAll('.input-field');
|
||||
const accessory = document.getElementById('keyboardAccessory');
|
||||
const cancelBtn = document.getElementById('cancelBtn');
|
||||
const clearBtn = document.getElementById('clearBtn');
|
||||
const confirmBtn = document.getElementById('confirmBtn');
|
||||
let activeInput = null;
|
||||
let isIOS = /iPhone|iPad|iPod/.test(navigator.userAgent);
|
||||
|
||||
// 键盘高度检测器
|
||||
class KeyboardManager {
|
||||
constructor() {
|
||||
this.height = 0;
|
||||
this.initialHeight = this.getVisualHeight();
|
||||
this.isVisible = false;
|
||||
this.init();
|
||||
}
|
||||
|
||||
getVisualHeight() {
|
||||
return window.visualViewport?.height || window.innerHeight;
|
||||
}
|
||||
|
||||
init() {
|
||||
if (window.visualViewport) {
|
||||
window.visualViewport.addEventListener('resize', () => this.update());
|
||||
}
|
||||
window.addEventListener('resize', () => this.update());
|
||||
}
|
||||
|
||||
update() {
|
||||
const currentHeight = this.getVisualHeight();
|
||||
const diff = this.initialHeight - currentHeight;
|
||||
|
||||
if (diff > 100 && !this.isVisible) {
|
||||
this.height = diff;
|
||||
this.isVisible = true;
|
||||
this.emit('show', this.height);
|
||||
} else if (diff <= 50 && this.isVisible) {
|
||||
this.initialHeight = currentHeight;
|
||||
this.isVisible = false;
|
||||
this.emit('hide');
|
||||
}
|
||||
}
|
||||
|
||||
on(type, callback) {
|
||||
this[type] = callback;
|
||||
}
|
||||
|
||||
emit(type, data) {
|
||||
if (this[type]) this[type](data);
|
||||
}
|
||||
}
|
||||
|
||||
const keyboard = new KeyboardManager();
|
||||
|
||||
// 键盘弹出时调整位置
|
||||
keyboard.on('show', (height) => {
|
||||
if (activeInput && isIOS) {
|
||||
accessory.style.bottom = `${height}px`;
|
||||
} else if (activeInput) {
|
||||
accessory.style.bottom = '0';
|
||||
}
|
||||
});
|
||||
|
||||
keyboard.on('hide', () => {
|
||||
accessory.style.bottom = '0';
|
||||
});
|
||||
|
||||
// 输入框聚焦/失焦
|
||||
inputs.forEach(input => {
|
||||
input.addEventListener('focus', (e) => {
|
||||
activeInput = e.target;
|
||||
accessory.classList.add('show');
|
||||
setTimeout(() => keyboard.update(), 300);
|
||||
});
|
||||
|
||||
input.addEventListener('blur', () => {
|
||||
setTimeout(() => {
|
||||
if (!document.activeElement.classList.contains('input-field')) {
|
||||
accessory.classList.remove('show');
|
||||
activeInput = null;
|
||||
}
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
|
||||
// 按钮事件
|
||||
cancelBtn.addEventListener('click', () => activeInput?.blur());
|
||||
clearBtn.addEventListener('click', () => {
|
||||
if (activeInput) {
|
||||
activeInput.value = '';
|
||||
activeInput.focus();
|
||||
}
|
||||
});
|
||||
confirmBtn.addEventListener('click', () => {
|
||||
if (activeInput) {
|
||||
alert(`输入内容:${activeInput.value || '空'}`);
|
||||
activeInput.blur();
|
||||
}
|
||||
});
|
||||
|
||||
// 禁止页面滚动时辅助栏偏移(可选)
|
||||
window.addEventListener('scroll', () => {
|
||||
if (accessory.classList.contains('show')) {
|
||||
// 强制重绘,避免滚动时的视觉偏移
|
||||
accessory.style.willChange = 'transform';
|
||||
setTimeout(() => {
|
||||
accessory.style.willChange = '';
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,247 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
||||
<title>iOS 适配键盘辅助栏</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
padding: 20px;
|
||||
padding-bottom: 60px;
|
||||
background-color: #f5f5f7;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
h3 {
|
||||
color: #1d1d1f;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 12px;
|
||||
font-size: 16px;
|
||||
background-color: white;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.input-field:focus {
|
||||
outline: none;
|
||||
border-color: #007aff;
|
||||
box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
|
||||
}
|
||||
|
||||
/* 键盘辅助栏核心样式 */
|
||||
.keyboard-accessory {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 55px;
|
||||
background-color: white;
|
||||
border-top: 1px solid #eee;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 16px;
|
||||
transition: transform 0.3s ease, bottom 0.3s ease;
|
||||
transform: translateY(100%); /* 默认隐藏 */
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.keyboard-accessory.show {
|
||||
transform: translateY(0); /* 显示时移出隐藏状态 */
|
||||
}
|
||||
|
||||
.accessory-btn {
|
||||
padding: 8px 20px;
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
color: #666;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
color: #333;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.confirm-btn {
|
||||
color: white;
|
||||
background-color: #007aff;
|
||||
}
|
||||
|
||||
/* 深色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body { background-color: #1c1c1e; }
|
||||
h3 { color: #f5f5f7; }
|
||||
.input-field {
|
||||
background-color: #2c2c2e;
|
||||
border-color: #3a3a3c;
|
||||
color: white;
|
||||
}
|
||||
.keyboard-accessory {
|
||||
background-color: #1c1c1e;
|
||||
border-top-color: #3a3a3c;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h3>iOS 键盘辅助栏(贴合键盘)</h3>
|
||||
<div class="input-group">
|
||||
<input
|
||||
type="text"
|
||||
class="input-field"
|
||||
placeholder="点击输入,辅助栏会贴合键盘..."
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 键盘辅助栏 -->
|
||||
<div class="keyboard-accessory" id="keyboardAccessory">
|
||||
<button class="accessory-btn cancel-btn" id="cancelBtn">取消</button>
|
||||
<button class="accessory-btn clear-btn" id="clearBtn">清除</button>
|
||||
<button class="accessory-btn confirm-btn" id="confirmBtn">完成</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 获取元素
|
||||
const inputs = document.querySelectorAll('.input-field');
|
||||
const accessory = document.getElementById('keyboardAccessory');
|
||||
const cancelBtn = document.getElementById('cancelBtn');
|
||||
const clearBtn = document.getElementById('clearBtn');
|
||||
const confirmBtn = document.getElementById('confirmBtn');
|
||||
let activeInput = null;
|
||||
let isIOS = /iPhone|iPad|iPod/.test(navigator.userAgent); // 检测iOS设备
|
||||
|
||||
// 键盘高度检测器(核心:动态计算键盘高度)
|
||||
class KeyboardManager {
|
||||
constructor() {
|
||||
this.height = 0;
|
||||
this.initialHeight = this.getVisualHeight();
|
||||
this.isVisible = false;
|
||||
this.init();
|
||||
}
|
||||
|
||||
// 获取视觉视口高度(iOS关键)
|
||||
getVisualHeight() {
|
||||
return window.visualViewport?.height || window.innerHeight;
|
||||
}
|
||||
|
||||
init() {
|
||||
// 监听视觉视口变化(iOS主要依赖这个)
|
||||
if (window.visualViewport) {
|
||||
window.visualViewport.addEventListener('resize', () => this.update());
|
||||
}
|
||||
// 监听传统resize(兼容Android)
|
||||
window.addEventListener('resize', () => this.update());
|
||||
}
|
||||
|
||||
update() {
|
||||
const currentHeight = this.getVisualHeight();
|
||||
const diff = this.initialHeight - currentHeight;
|
||||
|
||||
// 高度差>100px判定为键盘弹出(过滤屏幕旋转等干扰)
|
||||
if (diff > 100 && !this.isVisible) {
|
||||
this.height = diff;
|
||||
this.isVisible = true;
|
||||
this.emit('show', this.height);
|
||||
}
|
||||
// 高度差<50px判定为键盘收起
|
||||
else if (diff <= 50 && this.isVisible) {
|
||||
this.initialHeight = currentHeight; // 重置初始高度
|
||||
this.isVisible = false;
|
||||
this.emit('hide');
|
||||
}
|
||||
}
|
||||
|
||||
// 事件监听
|
||||
on(type, callback) {
|
||||
this[type] = callback;
|
||||
}
|
||||
|
||||
emit(type, data) {
|
||||
if (this[type]) this[type](data);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化键盘管理器
|
||||
const keyboard = new KeyboardManager();
|
||||
|
||||
// 键盘弹出时:调整辅助栏位置到键盘顶部
|
||||
keyboard.on('show', (height) => {
|
||||
if (activeInput && isIOS) {
|
||||
// iOS:辅助栏底部 = 键盘高度(使其悬浮在键盘顶部)
|
||||
accessory.style.bottom = `${height}px`;
|
||||
} else if (activeInput) {
|
||||
// Android:辅助栏固定在底部(会被键盘顶起)
|
||||
accessory.style.bottom = '0';
|
||||
}
|
||||
});
|
||||
|
||||
// 键盘收起时:重置辅助栏位置
|
||||
keyboard.on('hide', () => {
|
||||
accessory.style.bottom = '0';
|
||||
});
|
||||
|
||||
// 输入框聚焦:显示辅助栏
|
||||
inputs.forEach(input => {
|
||||
input.addEventListener('focus', (e) => {
|
||||
activeInput = e.target;
|
||||
accessory.classList.add('show');
|
||||
// 主动触发一次高度检测(解决iOS延迟问题)
|
||||
setTimeout(() => keyboard.update(), 300);
|
||||
});
|
||||
|
||||
input.addEventListener('blur', () => {
|
||||
setTimeout(() => {
|
||||
if (!document.activeElement.classList.contains('input-field')) {
|
||||
accessory.classList.remove('show');
|
||||
activeInput = null;
|
||||
}
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
|
||||
// 按钮事件
|
||||
cancelBtn.addEventListener('click', () => activeInput?.blur());
|
||||
clearBtn.addEventListener('click', () => {
|
||||
if (activeInput) {
|
||||
activeInput.value = '';
|
||||
activeInput.focus();
|
||||
}
|
||||
});
|
||||
confirmBtn.addEventListener('click', () => {
|
||||
if (activeInput) {
|
||||
alert(`输入内容:${activeInput.value || '空'}`);
|
||||
activeInput.blur();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
1
js/jweixin-1.6.0.js
Normal file
1
js/jweixin-1.6.0.js
Normal file
File diff suppressed because one or more lines are too long
@@ -1,227 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||
<title>H5 键盘辅助栏</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
padding: 20px;
|
||||
padding-bottom: 60px; /* 预留辅助栏空间 */
|
||||
background-color: #f5f5f7;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
h3 {
|
||||
color: #1d1d1f;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 12px;
|
||||
font-size: 16px;
|
||||
background-color: white;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.input-field:focus {
|
||||
outline: none;
|
||||
border-color: #007aff;
|
||||
box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
|
||||
}
|
||||
|
||||
.input-field::placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 键盘辅助栏样式 */
|
||||
.keyboard-accessory {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 55px;
|
||||
background-color: white;
|
||||
border-top: 1px solid #eee;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 16px;
|
||||
transition: transform 0.3s ease;
|
||||
transform: translateY(100%); /* 默认隐藏 */
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.keyboard-accessory.show {
|
||||
transform: translateY(0); /* 显示时移回底部 */
|
||||
}
|
||||
|
||||
.accessory-btn {
|
||||
padding: 8px 20px;
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.accessory-btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
color: #666;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
color: #333;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.confirm-btn {
|
||||
color: white;
|
||||
background-color: #007aff;
|
||||
}
|
||||
|
||||
/* 深色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body {
|
||||
background-color: #1c1c1e;
|
||||
}
|
||||
|
||||
h3 {
|
||||
color: #f5f5f7;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
background-color: #2c2c2e;
|
||||
border-color: #3a3a3c;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.input-field::placeholder {
|
||||
color: #8e8e93;
|
||||
}
|
||||
|
||||
.keyboard-accessory {
|
||||
background-color: #1c1c1e;
|
||||
border-top-color: #3a3a3c;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
color: #d1d1d6;
|
||||
background-color: #2c2c2e;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
color: #d1d1d6;
|
||||
background-color: #3a3a3c;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h3>键盘辅助栏示例</h3>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="text" class="input-field" id="mainInput" placeholder="点击输入内容..." />
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="text" class="input-field" placeholder="另一个输入框..." />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 键盘辅助栏 -->
|
||||
<div class="keyboard-accessory" id="keyboardAccessory">
|
||||
<button class="accessory-btn cancel-btn" id="cancelBtn">取消</button>
|
||||
<button class="accessory-btn clear-btn" id="clearBtn">清除</button>
|
||||
<button class="accessory-btn confirm-btn" id="confirmBtn">完成</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 获取DOM元素
|
||||
const inputs = document.querySelectorAll(".input-field");
|
||||
const keyboardAccessory = document.getElementById("keyboardAccessory");
|
||||
const cancelBtn = document.getElementById("cancelBtn");
|
||||
const clearBtn = document.getElementById("clearBtn");
|
||||
const confirmBtn = document.getElementById("confirmBtn");
|
||||
let activeInput = null; // 当前聚焦的输入框
|
||||
|
||||
// 输入框聚焦事件:显示辅助栏
|
||||
inputs.forEach((input) => {
|
||||
input.addEventListener("focus", (e) => {
|
||||
activeInput = e.target;
|
||||
keyboardAccessory.classList.add("show");
|
||||
});
|
||||
|
||||
input.addEventListener("blur", () => {
|
||||
// 延迟隐藏,确保按钮点击事件能触发
|
||||
setTimeout(() => {
|
||||
if (!document.activeElement.classList.contains("input-field")) {
|
||||
keyboardAccessory.classList.remove("show");
|
||||
activeInput = null;
|
||||
}
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
|
||||
// 取消按钮:收起键盘
|
||||
cancelBtn.addEventListener("click", () => {
|
||||
if (activeInput) {
|
||||
activeInput.blur();
|
||||
}
|
||||
});
|
||||
|
||||
// 清除按钮:清空当前输入框内容
|
||||
clearBtn.addEventListener("click", () => {
|
||||
if (activeInput) {
|
||||
activeInput.value = "";
|
||||
activeInput.focus(); // 保持聚焦状态
|
||||
}
|
||||
});
|
||||
|
||||
// 完成按钮:提交内容并收起键盘
|
||||
confirmBtn.addEventListener("click", () => {
|
||||
if (activeInput) {
|
||||
const value = activeInput.value.trim();
|
||||
if (value) {
|
||||
alert(`输入内容:${value}`);
|
||||
} else {
|
||||
alert("输入框为空");
|
||||
}
|
||||
activeInput.blur();
|
||||
}
|
||||
});
|
||||
|
||||
// 监听窗口大小变化,确保辅助栏位置正确
|
||||
window.addEventListener("resize", () => {
|
||||
if (activeInput) {
|
||||
keyboardAccessory.classList.add("show");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user