js 实现提示框

提示一:

在这里插入图片描述

提示二:

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">

<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>
</head>

<body>
    <!-- 唤起弹框元素 -->
    <button id="open-toast">唤起提示框元素</button>
    <!-- 提示元素选择自己需要的种类,删除掉另一个即可 -->
    <!-- 提示元素:标题+提示内容+关闭按钮 -->
    <div class="toast"
        style="display: none;width: 300px;border: 1px solid white;padding: 5px 15px;position: fixed;left: 50%;top: 50%;transform: translate(-50%, -50%);box-shadow: 0px 0px 10px #d3d3d3;border-radius: 5px;">
        <h3 class="toast-title" style="text-align: left;margin: 0;padding: 0;">标题</h3>
        <div class="toast-content">白底黑字内容</div>
        <div style="display: flex;justify-content: flex-end;">
            <button class="toast-close"
                style="background-color:#3c91f7;padding: 5px 30px;border: none;border-radius: 3px;color: white;">知道了</button>
        </div>
    </div>
    <!-- 提示元素:只需要提示内容 -->
    <span class="toast"
        style="display: none;background-color: #7f7f7f;border-radius: 5px;padding: 8px 40px;position: fixed;left: 50%;top: 50%;transform: translate(-50%, -50%);border: none;opacity: 0.9;color: #dadada;text-align: center;">
        黑底白字内容</span>
    <script>
        document.querySelector('#open-toast').onclick = function () {
            document.querySelector('.toast').style.display = ''
            // // 2 s后自动关闭 自动关闭和手动点击关闭二选一
            setTimeout(() => {
                document.querySelector('.toast').style.display = 'none'
            }, 2000);

        }
        // 手动点击"我知道了"关闭 自动关闭和手动点击关闭二选一
        document.querySelector('.toast-close').onclick = function () {
            document.querySelector('.toast').style.display = 'none'
        }
    </script>
</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

任平生01

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值