HTML+CSS+JS精美气泡提示框

源代码在效果图后面    点赞❤️关注💛收藏⭐️

主要实现:提示框出现和消失两种丝滑动画 弹出气泡提示框后延迟2秒自动消失 

效果图

错误框

fccea86ad539460b8e06b8f832b9e850.jpg

正确449077ea29a24893b7c9e51da14b6c7e.jpg

 警告

fbbbc4f3f96a4718ae8d909adb9a73bd.jpg

 提示

ada148f86006450f9b0c58a78a0f5fad.jpg

 源代码

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Web界面</title>
  <style>
    .panel {
      border-radius: 10px;
      margin: 10px 0;
      padding: 15px;
      cursor: pointer;
      box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    }

    .green {
      background-color: #e0f7e0;
      border: 2px solid #4caf50;
    }

    .red {
      background-color: #ffebee;
      border: 2px solid #f44336;
    }

    .orange {
      background-color: #fff3e0;
      border: 2px solid #ff9800;
    }

    .blue {
      background-color: #e3f2fd;
      border: 2px solid #2196f3;
    }

    .bubble {
      position: fixed;
      top: -100px;
      left: 50%;
      transform: translateX(-50%);
      padding: 15px 16px;
      border-radius: 10px;
      box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
      width: 300px;
      text-align: center;
      opacity: 0;
      transition: all 1s ease;
    }
  </style>
</head>
<body>
<h1>气泡提示框示例</h1>
<h3>警告框</h3>
<h3>提示框</h3>
<h3>错误框</h3>
<h3>正确框</h3>
  <div class="panel orange" onclick="showBubble('警告框')">点我弹出警告框</div>
  <div class="panel blue" onclick="showBubble('提示框')">点我弹出提示框</div>
  <div class="panel green" onclick="showBubble('正确框')">点我弹出正确框</div>
  <div class="panel red" onclick="showBubble('错误框')">点我弹出错误框</div>

  <div id="bubble" class="bubble"></div>

  <script>
    function showBubble(type) {
      let bubble = document.getElementById('bubble');
      bubble.classList.remove('green', 'red', 'orange', 'blue');
      bubble.classList.add(getClass(type));
      bubble.textContent = getContent(type);
      bubble.style.top = '80px';
      bubble.style.opacity = '1';

      setTimeout(function() {
        bubble.style.top = '-100px';
        bubble.style.opacity = '0';
      }, 2000);
    }

    function getClass(type) {
      switch (type) {
        case '警告框':
          return 'orange';
        case '提示框':
          return 'blue';
        case '正确框':
          return 'green';
        case '错误框':
          return 'red';
        default:
          return '';
      }
    }

    function getContent(type) {
      switch (type) {
        case '警告框':
          return '这是一个警告框';
        case '提示框':
          return '这是一个提示框';
        case '正确框':
          return '这是一个正确框';
        case '错误框':
          return '这是一个错误框';
        default:
          return '';
      }
    }
  </script>
</body>
</html>






 

 

  • 21
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

睿智的海鸥

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

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

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

打赏作者

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

抵扣说明:

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

余额充值