用 UniApp 打造新颖雅观的弹出框

一给  金牌会员 | 2025-2-19 17:21:34 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 988|帖子 988|积分 2964

 
在移动应用开发中,弹出框是一种常见且实用的交互组件,它可以大概有效地向用户展示重要信息或获取用户的反馈。UniApp 作为一款精良的跨平台开发框架,提供了强大的功能和丰富的样式支持,让我们可以轻松实现各种独特的界面效果。本文将详细先容如何使用 UniApp 实现一个新颖雅观的弹出框,接纳多巴胺配色方案,使界面更加活泼和吸引人。

  1. <template>
  2.   <view class="page-container">
  3.     <!-- 触发弹出框的按钮 -->
  4.     <button @click="showPopup = true">打开弹出框</button>
  5.     <!-- 弹出框组件 -->
  6.     <view class="popup-mask" v-if="showPopup" @click="closePopup">
  7.       <view class="popup-box" @click.stop>
  8.         <view class="popup-header">
  9.           <text>重要提示</text>
  10.           <button class="close-btn" @click="closePopup">×</button>
  11.         </view>
  12.         <view class="popup-content">
  13.           <text>这是一个弹出框示例,你可以在这里展示重要信息。</text>
  14.         </view>
  15.         <view class="popup-footer">
  16.           <button @click="closePopup">确认</button>
  17.         </view>
  18.       </view>
  19.     </view>
  20.   </view>
  21. </template>
  22. <script>
  23. export default {
  24.   data() {
  25.     return {
  26.       showPopup: false
  27.     };
  28.   },
  29.   methods: {
  30.     // 关闭弹出框的方法
  31.     closePopup() {
  32.       this.showPopup = false;
  33.     }
  34.   }
  35. };
  36. </script>
  37. /* 页面容器样式 */
  38. .page-container {
  39.   display: flex;
  40.   justify-content: center;
  41.   align-items: center;
  42.   height: 100vh;
  43. }
  44. /* 弹出框遮罩层样式 */
  45. .popup-mask {
  46.   position: fixed;
  47.   top: 0;
  48.   left: 0;
  49.   width: 100%;
  50.   height: 100%;
  51.   background-color: rgba(0, 0, 0, 0.5);
  52.   display: flex;
  53.   justify-content: center;
  54.   align-items: center;
  55.   animation: fadeIn 0.3s ease;
  56. }
  57. /* 弹出框主体样式 */
  58. .popup-box {
  59.   width: 80%;
  60.   max-width: 300px;
  61.   background: linear-gradient(to bottom, #f6d365, #fda085);
  62.   border-radius: 15px;
  63.   box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  64.   overflow: hidden;
  65.   position: relative;
  66. }
  67. /* 弹出框头部样式 */
  68. .popup-header {
  69.   padding: 15px;
  70.   color: white;
  71.   display: flex;
  72.   justify-content: center;
  73.   align-items: center;
  74. }
  75. /* 关闭按钮样式 */
  76. .close-btn {
  77.   position: absolute;
  78.   top: 10px;
  79.   right: 10px;
  80.   background: none;
  81.   border: none;
  82.   font-size: 24px;
  83.   color: white;
  84.   cursor: pointer;
  85.   outline: none;
  86. }
  87. /* 弹出框内容区域样式 */
  88. .popup-content {
  89.   padding: 20px;
  90.   text-align: center;
  91.   color: #333;
  92. }
  93. /* 弹出框底部样式 */
  94. .popup-footer {
  95.   display: flex;
  96.   justify-content: center;
  97.   padding: 15px;
  98.   border-top: 1px solid rgba(255, 255, 255, 0.5);
  99. }
  100. .popup-footer button {
  101.   background-color: #f6d365;
  102.   border: none;
  103.   padding: 10px 20px;
  104.   border-radius: 5px;
  105.   color: white;
  106.   font-weight: bold;
  107.   cursor: pointer;
  108.   box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  109. }
  110. /* 淡入动画关键帧 */
  111. @keyframes fadeIn {
  112.   from {
  113.     opacity: 0;
  114.   }
  115.   to {
  116.     opacity: 1;
  117.   }
  118. }
复制代码
 
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

一给

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表