zoukankan      html  css  js  c++  java
  • 纯css写一个带动画的弹框 visibility + opcity

    css能实现各种各样的动态效果,比js实现简单,性能也比js实现高,现在我们就用纯css实现弹窗,主要用到了两个属性 opcity 和 visibility,

    opctiy 这个属性很简单 控制元素透明度 ,visibility控制元素的显示和隐藏,他和display有一个很重要的区别,visibility可以用transition来进行过渡,而display并不可以,这就是我们不用display的原因

    可以配合上transform: scale() 让弹窗更有动态感觉

     

    全部代码:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>纯css弹窗动画</title>
    </head>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
    
    
      .alert-box {
        top: 0;
        left: 0;
        z-index: 999;
        position: fixed;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.3);
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 16px;
        visibility: hidden;
        opacity: 0;
        transition: all 0.3s ease-in-out;
      }
    
      .alert-content {
        height: 130px;
        width: 300px;
        background-color: #ffffff;
        border-radius: 10px;
        padding: 12px 18px;
        transform: scale(0.8);
        transition: all 0.3s ease-in-out;
      }
    
      .alert-title {
        height: 50px;
        line-height: 50px;
        font-size: 18px;
      }
    
      .alert-info {
        height: 50px;
        line-height: 50px;
        font-size: 16px;
      }
    
      .alert-buttons {
        display: flex;
        justify-content: flex-end;
        font-size: 16px;
      }
    
      .alert-buttons>div {
        height: 30px;
        line-height: 30px;
        margin-left: 17px;
        width: 56px;
        text-align: center;
        font-size: 16px;
        border-radius: 3px;
        cursor: pointer;
      }
    
      .alert-submit {
        background: #409eff;
        color: #fff;
      }
    
      .alert-cancle {
        border: 1px solid #ccc;
    
      }
    
      .open {
        margin: 20px;
        height: 30px;
        width: 50px;
      }
    
      .show {
        visibility: visible;
        opacity: 1;
      }
    
      .show .alert-content {
        transform: scale(1);
      }
    
    </style>
    
    <body>
      <button class="open" onclick="openAlert()"> 打开 </button>
      <div class="alert-box" id="alertBox">
        <div class="alert-content">
          <div class="alert-title">提示</div>
          <div class="alert-info">提示框的内容</div>
          <div class="alert-buttons">
            <div class="alert-cancle" onclick="hiddenAlert()">取消</div>
            <div class="alert-submit" onclick="hiddenAlert()">确定</div>
          </div>
        </div>
      </div>
    </body>
    
    <script>
    
      function openAlert() {
        document.getElementById("alertBox").classList.add('show')
      }
      function hiddenAlert() {
        document.getElementById("alertBox").classList.remove('show')
      }
    </script>
    
    </html>
    View Code
  • 相关阅读:
    了解 NoSQL 的必读资料
    关于什么时候用assert(断言)的思考
    这次见到了一些大侠
    NetBeans 时事通讯(刊号 # 87 Jan 12, 2010)
    动态链接库dll,静态链接库lib, 导入库lib
    新女性十得 写得了代码,查得出异常
    记录系统乱谈
    新女性十得 写得了代码,查得出异常
    fullpage.js禁止滚动
    RunningMapReduceExampleTFIDF hadoopclusternet This document describes how to run the TFIDF MapReduce example against ascii books. This project is for those who wants to experiment hadoop as a skunkworks in a small cluster (110 nodes) Google Pro
  • 原文地址:https://www.cnblogs.com/Qqqing/p/12588386.html
Copyright © 2011-2022 走看看