原生弹框2(vue)

html、css、js

<template>
  <div class="about">
    <button id="modal" @click="appear">点击弹窗</button>
    <div class="container" id="modalContent" v-show="status">
      <div class="modalbg"></div>
      <div
        class="content"
        style=" width: 300px;height: 200px; z-index: 110;position: relative; left: 50%;top: 50%;transform: translate(-50%); background-color: #fff;"
      >
        <div
          style="background-color: #F8F8F8; padding: 10px;display: flex; align-items: center;justify-content: space-between;"
        >
          <span>详情弹框</span>
          <img
            src="../assets/images/u291.svg"
            alt
            style="width: 16px;height: 16px; cursor: pointer;"
            id="close"
            @click="close"
          />
        </div>
        <div class="content" style="padding: 10px;">
          详情内容
          <!-- <img src="../../图片/20141101200820_imLnw.jpeg" style="width: 500px;height: 500px;"  alt=""> -->
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      status: false
    };
  },
  methods: {
    close() {
      this.status = false;
    },
    appear() {
      // alert("132")
      this.status = true;
    }
  }
};
</script>
<style lang="scss">
.container {
  width: 100%;
  height: 100%;
  // display: none;
}

.modalbg {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 100;
  background-color: rgb(0, 0, 0);
  opacity: 0.3;
}
</style>

小结:
弹框 样式思路

  1. btn 触发弹窗的按钮,其实就是来控制display:none和block切换的问题
  2. container 弹窗以及里面的内容包括。我们把它设置给 宽高为100%,也就是遮罩层覆盖整个页面
  3. modalbg 弹窗样式 固定定位、宽高100%、z-index background-color: rgb(0, 0, 0); opacity: 0.3;
  4. content 要写的内容,自己定义即可
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值