[HTML] 纯文本查看 复制代码
<!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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
color: #333;
min-height: 100vh;
padding: 20px;
transition: all 0.3s ease;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
overflow: hidden;
position: relative;
}
header {
background: #2c3e50;
color: white;
padding: 20px;
text-align: center;
}
h1 {
font-size: 2.2rem;
margin-bottom: 10px;
}
.description {
font-size: 1.1rem;
opacity: 0.9;
max-width: 800px;
margin: 0 auto;
line-height: 1.6;
}
.controls {
padding: 20px;
background: #f8f9fa;
display: flex;
justify-content: center;
gap: 15px;
border-bottom: 1px solid #eaeaea;
}
button {
padding: 12px 24px;
border: none;
border-radius: 6px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
gap: 8px;
}
#enableClick {
background: #2ecc71;
color: white;
}
#disableClick {
background: #e74c3c;
color: white;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.content {
padding: 30px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
}
.card {
background: white;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
padding: 20px;
border: 1px solid #eaeaea;
transition: all 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}
.card h2 {
color: #2c3e50;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 2px solid #f0f0f0;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: 600;
color: #555;
}
input, textarea, select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
transition: border 0.3s;
}
input:focus, textarea:focus, select:focus {
border-color: #3498db;
outline: none;
}
.btn-group {
display: flex;
gap: 10px;
margin-top: 20px;
}
.btn {
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: 600;
}
.btn-primary {
background: #3498db;
color: white;
}
.btn-secondary {
background: #95a5a6;
color: white;
}
.clickable-item {
padding: 12px 15px;
background: #f8f9fa;
border-radius: 6px;
margin-bottom: 10px;
cursor: pointer;
transition: background 0.2s;
border-left: 4px solid #3498db;
}
.clickable-item:hover {
background: #e9ecef;
}
.status-bar {
position: fixed;
top: 0;
left: 0;
width: 100%;
padding: 12px;
text-align: center;
font-weight: bold;
font-size: 1.1rem;
z-index: 1000;
display: none;
}
.disabled-status {
background: rgba(231, 76, 60, 0.9);
color: white;
}
.enabled-status {
background: rgba(46, 204, 113, 0.9);
color: white;
}
.no-pointer-events {
pointer-events: none;
}
.no-pointer-events .card:hover {
transform: none;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.no-pointer-events .clickable-item:hover {
background: #f8f9fa;
}
.no-pointer-events input,
.no-pointer-events textarea,
.no-pointer-events select,
.no-pointer-events button {
opacity: 0.7;
}
footer {
text-align: center;
padding: 20px;
background: #2c3e50;
color: white;
margin-top: 30px;
}
@media (max-width: 768px) {
.content {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>页面不可点击效果演示</h1>
<p class="description">这个页面展示了如何使用CSS的pointer-events属性使页面内容可见但无法点击。点击下面的按钮来切换状态。</p>
</header>
<div class="controls">
<button id="disableClick">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 11a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>
<path d="M13.997 5.17a5 5 0 0 0-8.101-4.09A5 5 0 0 0 1.28 9.342a5 5 0 0 0 8.336 5.109 3.5 3.5 0 0 0 5.201-4.065 3.001 3.001 0 0 0-.822-5.216zm-1.033 11.297A6 6 0 0 1 7.9 15.41 6 6 0 0 1 6.8 5.491a6 6 0 0 1 9.8 4.93 1.5 1.5 0 0 1-2.536 1.738 1 1 0 0 0-1.676-.933.5.5 0 0 1-.78-.616 4 4 0 0 0 4.442-6.539 4 4 0 0 0-6.187.645.5.5 0 0 1-.78.616 3 3 0 0 0-4.134 4.308 3 3 0 0 0 4.91 3.137.5.5 0 0 1 .78.616 2 2 0 0 1-2.67 2.689 2 2 0 0 1 2.847-2.847.5.5 0 0 1 .78.616 1 1 0 0 0 1.676.933 2.5 2.5 0 0 0 3.536-3.455z"/>
</svg>
禁用点击
</button>
<button id="enableClick">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 11a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>
<path d="M0 8s3-5.5 8-5.5S16 8 16 8s-3 5.5-8 5.5S0 8 0 8zm8 3.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z"/>
</svg>
启用点击
</button>
</div>
<div class="status-bar disabled-status" id="statusBar">
页面点击功能已被禁用
</div>
<div class="content" id="pageContent">
<div class="left-column">
<div class="card">
<h2>用户信息表单</h2>
<div class="form-group">
<label for="name">姓名</label>
<input type="text" id="name" placeholder="请输入您的姓名">
</div>
<div class="form-group">
<label for="email">电子邮箱</label>
<input type="email" id="email" placeholder="请输入您的邮箱">
</div>
<div class="form-group">
<label for="phone">手机号码</label>
<input type="tel" id="phone" placeholder="请输入您的手机号">
</div>
<div class="form-group">
<label for="country">国家</label>
<select id="country">
<option value="">请选择国家</option>
<option value="china">中国</option>
<option value="usa">美国</option>
<option value="uk">英国</option>
<option value="japan">日本</option>
</select>
</div>
<div class="form-group">
<label for="message">留言</label>
<textarea id="message" rows="4" placeholder="请输入您的留言"></textarea>
</div>
<div class="btn-group">
<button class="btn btn-primary">提交</button>
<button class="btn btn-secondary">重置</button>
</div>
</div>
<div class="card">
<h2>交互元素示例</h2>
<div class="clickable-item">可点击项目 1</div>
<div class="clickable-item">可点击项目 2</div>
<div class="clickable-item">可点击项目 3</div>
<div class="clickable-item">可点击项目 4</div>
<div class="clickable-item">可点击项目 5</div>
</div>
</div>
<div class="right-column">
<div class="card">
<h2>产品列表</h2>
<div class="product-list">
<div class="clickable-item">
<strong>笔记本电脑</strong>
<p>高性能笔记本电脑,适合办公和游戏</p>
<button class="btn btn-primary" style="margin-top: 10px;">查看详情</button>
</div>
<div class="clickable-item">
<strong>智能手机</strong>
<p>最新款智能手机,拥有出色的摄像头</p>
<button class="btn btn-primary" style="margin-top: 10px;">查看详情</button>
</div>
<div class="clickable-item">
<strong>平板电脑</strong>
<p>轻薄便携的平板电脑,适合阅读和娱乐</p>
<button class="btn btn-primary" style="margin-top: 10px;">查看详情</button>
</div>
</div>
</div>
<div class="card">
<h2>操作面板</h2>
<div class="btn-group" style="flex-wrap: wrap;">
<button class="btn btn-primary">保存</button>
<button class="btn btn-secondary">编辑</button>
<button class="btn" style="background: #e74c3c; color: white;">删除</button>
<button class="btn" style="background: #f39c12; color: white;">分享</button>
<button class="btn" style="background: #9b59b6; color: white;">打印</button>
<button class="btn" style="background: #1abc9c; color: white;">导出</button>
</div>
<div style="margin-top: 20px;">
<label>
<input type="checkbox" id="agree">
我同意服务条款
</label>
</div>
<div style="margin-top: 15px;">
<label>
<input type="radio" name="option" value="1">
选项一
</label>
<label style="margin-left: 15px;">
<input type="radio" name="option" value="2">
选项二
</label>
</div>
</div>
</div>
</div>
<footer>
<p>页面不可点击效果示例 © 2023</p>
</footer>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const pageContent = document.getElementById('pageContent');
const disableClickBtn = document.getElementById('disableClick');
const enableClickBtn = document.getElementById('enableClick');
const statusBar = document.getElementById('statusBar');
// 初始状态:禁用点击
pageContent.classList.add('no-pointer-events');
statusBar.style.display = 'block';
statusBar.textContent = '页面点击功能已被禁用';
statusBar.className = 'status-bar disabled-status';
// 禁用点击功能
disableClickBtn.addEventListener('click', function() {
pageContent.classList.add('no-pointer-events');
statusBar.style.display = 'block';
statusBar.textContent = '页面点击功能已被禁用';
statusBar.className = 'status-bar disabled-status';
// 3秒后隐藏状态栏
setTimeout(() => {
statusBar.style.display = 'none';
}, 3000);
});
// 启用点击功能
enableClickBtn.addEventListener('click', function() {
pageContent.classList.remove('no-pointer-events');
statusBar.style.display = 'block';
statusBar.textContent = '页面点击功能已启用';
statusBar.className = 'status-bar enabled-status';
// 3秒后隐藏状态栏
setTimeout(() => {
statusBar.style.display = 'none';
}, 3000);
});
// 为页面元素添加一些交互反馈
const clickableItems = document.querySelectorAll('.clickable-item, button:not(#disableClick):not(#enableClick)');
clickableItems.forEach(item => {
item.addEventListener('click', function() {
if (!pageContent.classList.contains('no-pointer-events')) {
alert('您点击了: ' + (this.textContent || this.innerText).trim().substring(0, 20) + '...');
}
});
});
});
</script>
</body>
</html>