当前位置:首页 > CSS

css制作锁屏页面

2026-01-08 19:45:31CSS

css制作锁屏页面

使用CSS制作锁屏页面

锁屏页面通常包含一个背景、时间显示以及可能的解锁按钮或输入框。以下是实现锁屏页面的关键CSS代码和结构。

HTML结构

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>锁屏页面</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="lock-screen">
        <div class="time-display">
            <span id="hours">00</span>:<span id="minutes">00</span>
        </div>
        <div class="unlock-button">滑动解锁</div>
    </div>
    <script src="script.js"></script>
</body>
</html>

CSS样式

body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    overflow: hidden;
}

.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 1000;
}

.time-display {
    font-size: 5rem;
    font-weight: bold;
    margin-bottom: 2rem;
}

.unlock-button {
    padding: 15px 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    cursor: pointer;
    user-select: none;
    transition: background 0.3s;
}

.unlock-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

JavaScript动态时间

function updateTime() {
    const now = new Date();
    document.getElementById('hours').textContent = String(now.getHours()).padStart(2, '0');
    document.getElementById('minutes').textContent = String(now.getMinutes()).padStart(2, '0');
}

setInterval(updateTime, 1000);
updateTime(); // 初始化时间

添加滑动解锁功能

const unlockButton = document.querySelector('.unlock-button');
let startX, currentX;

unlockButton.addEventListener('touchstart', (e) => {
    startX = e.touches[0].clientX;
});

unlockButton.addEventListener('touchmove', (e) => {
    currentX = e.touches[0].clientX;
    const diff = currentX - startX;
    if (diff > 0) {
        unlockButton.style.transform = `translateX(${Math.min(diff, 150)}px)`;
    }
});

unlockButton.addEventListener('touchend', () => {
    if (parseInt(unlockButton.style.transform.replace('translateX(', '')) > 100) {
        document.querySelector('.lock-screen').style.display = 'none';
    }
    unlockButton.style.transform = 'translateX(0)';
});

响应式设计优化

@media (max-width: 600px) {
    .time-display {
        font-size: 3rem;
    }

    .unlock-button {
        padding: 12px 30px;
    }
}

这些代码创建了一个全屏锁屏界面,包含动态显示的时间和一个可滑动的解锁按钮。背景使用渐变色增强视觉效果,时间每秒钟自动更新,滑动解锁按钮向右滑动超过100px时会隐藏锁屏界面。

css制作锁屏页面

标签: 页面css
分享给朋友:

相关文章

vue如何实现默认页面

vue如何实现默认页面

实现 Vue 默认页面的方法 在 Vue 中实现默认页面通常涉及路由配置。以下是几种常见的方法: 使用路由重定向 在 Vue Router 配置中,可以通过 redirect 属性设置默认路由:…

vue页面实现

vue页面实现

Vue 页面实现方法 创建 Vue 组件 使用 Vue 单文件组件(SFC)方式创建页面,文件扩展名为 .vue。一个基本的 Vue 组件包含三个部分:模板(template)、脚本(script)和…

vue实现 页面

vue实现 页面

Vue 实现页面的核心方法 创建 Vue 项目 使用 Vue CLI 或 Vite 快速初始化项目。Vue CLI 是官方脚手架工具,适合传统项目;Vite 提供更快的现代构建体验。 npm cre…

vue实现页面

vue实现页面

Vue 实现页面的基本方法 创建 Vue 项目 使用 Vue CLI 快速初始化项目,运行以下命令安装并创建项目: npm install -g @vue/cli vue create my-pr…

vue实现结算页面

vue实现结算页面

Vue 实现结算页面的核心步骤 数据绑定与表单验证 使用 Vue 的 v-model 绑定表单数据,例如收货地址、支付方式等。通过 Vue 的 computed 属性计算总价,结合 v-if 或 v-…

vue页面实现日历

vue页面实现日历

Vue 页面实现日历的方法 使用第三方组件库 推荐使用成熟的日历组件库,如 v-calendar 或 fullcalendar-vue,快速实现功能丰富的日历。 安装 v-calendar: np…