案例--点击方块变形出时间

在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <div id="box">
        <div class="box2">
            <h3>点击我会出现时间</h3>
        </div>
    </div>

    <script>
        // 用来描述程序的行为和状态的改变,触发一系列回调函数的响应
        // 事件源.addEventListener('事件类型',回调函数)
        // 控制整体样式
        let box = document.getElementById('box')
        box.style.cssText = ('width: 200px; height: 200px; background-color: aqua; margin: 100px auto;transition: all .4s;text-align: center; line-height: 200px;')
        let box2 = document.querySelector('.box2')
        box2.style.display = 'none'
        let i = true
        // 控制时间
        setInterval(function () {
            let time = {
                author: 'jikel',
                date: new Date(),
                year: function () {
                    return this.date.getFullYear()
                },
                month: function () {
                    let month1 = this.date.getMonth() + 1
                    month1 = month1 < 10 ? '0' + month1 : month1
                    return month1
                },
                week: function () {
                    return this.date.getDate()
                },
                day: function () {
                    let day1 = this.date.getDate()
                    day1 = day1 < 10 ? '0' + day1 : day
                    return day1
                },
                h: function () {
                    let h1 = this.date.getHours()
                    h1 = h1 < 10 ? '0' + h1 : h1
                    return h1
                },
                f: function () {
                    let f1 = this.date.getMinutes()
                    f1 = f1 < 10 ? "0" + f1 : f1
                    return f1
                },
                s: function () {
                    let s1 = this.date.getSeconds()
                    s1 = s1 < 10 ? "0" + s1 : s1
                    return s1
                }
            }
            box2.innerHTML = `今日时间 -- ${time.h()}:${time.f()}:${time.s()}`
        }, 1000)
        // 点击事件
        box.addEventListener('click', function () {

            if (i) {
                box.style.borderRadius = '50px'
                box.style.boxShadow = ' 0px 5px 10px 3px #D1D1D1'
                box.style.backgroundColor = 'gold'
                box.style.transform = 'scale(1.5)'
                box2.style.display = 'block'
                i = false
            } else {
                box.style.borderRadius = '0px'
                box.style.boxShadow = ' 0px 0px 0px 0px #D1D1D1 '
                box.style.backgroundColor = 'aqua'
                box.style.transform = 'scale(1)'
                box2.style.display = 'none'
                i = true
            }

        })
    </script>
</body>

</html>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值