Web前端第三次作业

Web前端第三次作业

lottery.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>
    <link rel="stylesheet" href="lottery.css">
</head>
<body>
    <div class="container">
        <h1>幸运大转盘</h1>
        <div class="wheel">
            <div class="wheel-item" data-value="一等奖">一等奖</div>
            <div class="wheel-item" data-value="二等奖">二等奖</div>
            <div class="wheel-item" data-value="三等奖">三等奖</div>
            <div class="wheel-item" data-value="谢谢参与">谢谢参与</div>
            <div class="wheel-item" data-value="五等奖">五等奖</div>
            <div class="wheel-item" data-value="六等奖">六等奖</div>
            <div class="wheel-pointer"></div>
        </div>
        <button id="spin-btn">开始抽奖</button>
        <div id="result"></div>
    </div>
    <script src="lottery.js"></script>
</body>
</html>

lottery.css

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    overflow: hidden;
}

.container {
    text-align: center;
    background: rgba(255, 255, 255, 0.9);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    max-width: 500px;
    width: 90%;
}

h1 {
    color: #ff4757;
    margin-bottom: 1.5rem;
    font-size: 2rem;
}

.wheel {
    position: relative;
    width: 300px;
    height: 300px;
    margin: 0 auto 2rem;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    border: 10px solid #ff4757;
}

.wheel-item {
    position: absolute;
    width: 50%;
    height: 50%;
    transform-origin: 100% 100%;
    left: 0;
    top: 0;
    text-align: center;
    line-height: 150px;
    font-weight: bold;
    color: white;
    font-size: 1.2rem;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.wheel-item:nth-child(1) {
    background: linear-gradient(45deg, #ff4757, #ff6b81);
    transform: rotate(0deg) skewY(30deg);
}

.wheel-item:nth-child(2) {
    background: linear-gradient(45deg, #ff6b81, #ff8d8d);
    transform: rotate(60deg) skewY(30deg);
}

.wheel-item:nth-child(3) {
    background: linear-gradient(45deg, #ff8d8d, #ffa502);
    transform: rotate(120deg) skewY(30deg);
}

.wheel-item:nth-child(4) {
    background: linear-gradient(45deg, #ffa502, #ffb142);
    transform: rotate(180deg) skewY(30deg);
}

.wheel-item:nth-child(5) {
    background: linear-gradient(45deg, #ffb142, #ffcc33);
    transform: rotate(240deg) skewY(30deg);
}

.wheel-item:nth-child(6) {
    background: linear-gradient(45deg, #ffcc33, #ffdd59);
    transform: rotate(300deg) skewY(30deg);
}

.wheel-pointer {
    position: absolute;
    width: 40px;
    height: 40px;
    background: #ff4757;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    border: 4px solid white;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

#spin-btn {
    padding: 12px 30px;
    background: linear-gradient(45deg, #ff4757, #ff6b81);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(255, 71, 87, 0.4);
}

#spin-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(255, 71, 87, 0.6);
}

#spin-btn:active {
    transform: translateY(0);
}

#result {
    margin-top: 1.5rem;
    font-size: 1.3rem;
    font-weight: bold;
    color: #ff4757;
    min-height: 30px;
}

lottery.js

document.addEventListener('DOMContentLoaded', function() {
    const wheel = document.querySelector('.wheel');
    const spinBtn = document.getElementById('spin-btn');
    const resultDisplay = document.getElementById('result');
    let isSpinning = false;

    spinBtn.addEventListener('click', function() {
        if (isSpinning) return;
        isSpinning = true;
        resultDisplay.textContent = '';
        const prizes = ['一等奖', '二等奖', '三等奖', '谢谢参与', '五等奖', '六等奖'];
        const randomIndex = Math.floor(Math.random() * prizes.length);
        const selectedPrize = prizes[randomIndex];

        // 计算旋转角度(确保指针指向选中的奖项)
        const rotationAngle = 3600 + (randomIndex * 60); // 3600度表示多转几圈

        // 应用旋转动画
        wheel.style.transition = 'transform 4s ease-out';
        wheel.style.transform = `rotate(${-rotationAngle}deg)`;
        setTimeout(function() {
            resultDisplay.textContent = `恭喜你获得:${selectedPrize}`;
            isSpinning = false;
        }, 4000);
    });
    wheel.addEventListener('transitionend', function() {
        wheel.style.transition = 'none';
        const currentRotation = parseInt(wheel.style.transform.replace(/[^0-9-]/g, '')) || 0;
        wheel.style.transform = `rotate(${currentRotation % 360}deg)`;
        setTimeout(() => {
            wheel.style.transition = 'transform 4s ease-out';
        }, 10);
    });
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值