微信小程序弹窗

这篇具有很好参考价值的文章主要介绍了微信小程序弹窗。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

微信小程序自定义底部、顶部、中间、左边、右边弹窗
简单的微信小程序弹窗功能,具体实现过程,请浏览代码。
微信小程序弹窗
顶部弹出窗图例:
微信小程序弹窗
中间弹出窗图例:
微信小程序弹窗
底部弹出窗图例:
微信小程序弹窗
左边弹出窗图例:
微信小程序弹窗
右边弹出窗图例:
微信小程序弹窗

  1. wxml代码
<button type="primary" bindtap="openPopup" data-index="0">打开顶部弹窗</button>
<button type="primary" bindtap="openPopup" data-index="1">打开中间弹窗</button>
<button type="primary" bindtap="openPopup" data-index="2">打开底部弹窗</button>
<button type="primary" bindtap="openPopup" data-index="3">打开左边弹窗</button>
<button type="primary" bindtap="openPopup" data-index="4">打开右边弹窗</button>
<!-- 顶部弹窗 -->
<view class="popup-box" wx:if="{{showIndex=='0'}}" bindtap="closePopup"></view> 
<view class="info-top" wx:if="{{showIndex=='0'}}">
  <view class="row-info">
    <view>
      <text class="line left-line"></text>
      <text>《登高》</text>
      <text class="line right-line"></text>
    </view>
    <view class="row-author">杜甫 〔唐代〕</view>
    <view>风急天高猿啸哀,渚清沙白鸟飞回。</view>
    <view>无边落木萧萧下,不尽长江滚滚来。</view>
    <view>万里悲秋常作客,百年多病独登台。</view>
    <view>艰难苦恨繁霜鬓,潦倒新停浊酒杯。</view>
  </view>
  <view class="row-btn">
    <view class="left-btn" bindtap="closePopup">取消</view>
    <view class="right-btn">确认</view>
  </view>
</view>
<!-- 中间弹窗 -->
<view class="popup-box" wx:if="{{showIndex=='1'}}" bindtap="closePopup"></view> 
<view class="info-center" style="top:{{height*0.3}}px;height:{{height*0.4}}px;"
wx:if="{{showIndex=='1'}}">
  <view>
    <view class="row-info">
      <view>
        <text class="line left-line"></text>
        <text>《登高》</text>
        <text class="line right-line"></text>
      </view>
      <view class="row-author">杜甫 〔唐代〕</view>
      <view>风急天高猿啸哀,渚清沙白鸟飞回。</view>
      <view>无边落木萧萧下,不尽长江滚滚来。</view>
      <view>万里悲秋常作客,百年多病独登台。</view>
      <view>艰难苦恨繁霜鬓,潦倒新停浊酒杯。</view>
    </view>
    <view class="row-btn">
      <view class="left-btn" bindtap="closePopup">取消</view>
      <view class="right-btn">确认</view>
    </view>
  </view>
</view>
<!-- 底部弹窗 -->
<view class="popup-box" wx:if="{{showIndex=='2'}}" bindtap="closePopup"></view> 
<view class="info-bottom" wx:if="{{showIndex=='2'}}">
  <view class="row-info">
    <view>
      <text class="line left-line"></text>
      <text>《登高》</text>
      <text class="line right-line"></text>
    </view>
    <view class="row-author">杜甫 〔唐代〕</view>
    <view>风急天高猿啸哀,渚清沙白鸟飞回。</view>
    <view>无边落木萧萧下,不尽长江滚滚来。</view>
    <view>万里悲秋常作客,百年多病独登台。</view>
    <view>艰难苦恨繁霜鬓,潦倒新停浊酒杯。</view>
  </view>
  <view class="row-btn">
    <view class="left-btn" bindtap="closePopup">取消</view>
    <view class="right-btn">确认</view>
  </view>
</view>

<!-- 左边弹窗 -->
<view class="popup-box" wx:if="{{showIndex=='3'}}" bindtap="closePopup"></view> 
<view class="info-left" wx:if="{{showIndex=='3'}}">
  <view class="row-info">
    <view>
      <text class="line left-line"></text>
      <text>《登高》</text>
      <text class="line right-line"></text>
    </view>
    <view class="row-author">杜甫 〔唐代〕</view>
    <view>风急天高猿啸哀,</view>
    <view>渚清沙白鸟飞回。</view>
    <view>无边落木萧萧下,</view>
    <view>不尽长江滚滚来。</view>
    <view>万里悲秋常作客,</view>
    <view>百年多病独登台。</view>
    <view>艰难苦恨繁霜鬓,</view>
    <view>潦倒新停浊酒杯。</view>
  </view>
  <view class="row-btn fixed">
    <view class="left-btn" bindtap="closePopup">取消</view>
    <view class="right-btn">确认</view>
  </view>
</view>
<!-- 右边弹窗 -->
<view class="popup-box" wx:if="{{showIndex=='4'}}" bindtap="closePopup"></view> 
<view class="info-right" wx:if="{{showIndex=='4'}}">
  <view class="row-info">
    <view>
      <text class="line left-line"></text>
      <text>《登高》</text>
      <text class="line right-line"></text>
    </view>
    <view class="row-author">杜甫 〔唐代〕</view>
    <view>风急天高猿啸哀,</view>
    <view>渚清沙白鸟飞回。</view>
    <view>无边落木萧萧下,</view>
    <view>不尽长江滚滚来。</view>
    <view>万里悲秋常作客,</view>
    <view>百年多病独登台。</view>
    <view>艰难苦恨繁霜鬓,</view>
    <view>潦倒新停浊酒杯。</view>
  </view>
  <view class="row-btn fixed">
    <view class="left-btn" bindtap="closePopup">取消</view>
    <view class="right-btn">确认</view>
  </view>
</view>
  1. wxss代码
/* 蒙层 */
.popup-box{
  position: absolute;
  z-index: 99;
  top: 0;
  background-color: rgba(0, 0, 0, 0.5);
  width: 100%;
  height: 100%;
}
/* 上 */
.info-top{
  position: fixed;
  z-index: 999;
  width: 100%;
  top: 0;
  background-color: white;
  border-bottom-left-radius: 5rpx;
  border-bottom-right-radius: 5rpx;
}
/* 中 */
.info-center{
  position: fixed;
  z-index: 999;
  background-color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10rpx;
  width: 90%;
  margin-left: 5%;
  margin-right: 5%;
}
/* 下 */
.info-bottom{
  position: fixed;
  z-index: 999;
  width: 100%;
  bottom: 0;
  background-color: white;
  border-top-left-radius: 10rpx;
  border-top-right-radius: 10rpx;
}
/* 左 */
.info-left{
  position: fixed;
  z-index: 999;
  width: 50%;
  height: 100%;
  top: 0;
  background-color: white;
  border-top-right-radius: 10rpx;
  border-bottom-right-radius: 10rpx;
}
/* 右 */
.info-right{
  position: fixed;
  z-index: 999;
  width: 50%;
  height: 100%;
  right: 0;
  top: 0;
  background-color: white;
  border-top-left-radius: 10rpx;
  border-bottom-left-radius: 10rpx;
}
/* 自定义内容(根据自己需求更改,可删除) */
button{
  margin: 15rpx 0;
}
.row-info{
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 15rpx;
  font-size: 32rpx;
}
.row-info view{
  padding: 10rpx 0;
}
.row-info view:first-child{
  display: flex;
  flex-direction: row;
  align-items: center;
}
.line{
  width: 100rpx;
  height: 1rpx;
}
.left-line{
  background-image: linear-gradient(to left,orange,white);
}
.right-line{
  background-image: linear-gradient(to right,orange,white);
}
.row-author{
  font-size: 24rpx;
  color: gray;
}
.row-btn{
  display: flex;
  flex-direction: row;
  align-items: center;
  border-top: 1rpx dashed #f1f1f1;
}
.row-btn view{
  flex: 1;
  text-align: center;
  margin: 20rpx 10%;
  padding: 12rpx 0;
  font-size: 32rpx;
  border-radius: 10rpx;
}
.left-btn{
  background-color: #f1f1f1;
  color: #33ccff;
}
.right-btn{
  background-color: #33ccff;
  color: white;
}
.fixed{
  position: fixed;
  bottom: 0;
  width: 50%;
}
  1. js代码
Page({
  /**
   * 页面的初始数据
   */
  data: {
    showIndex:null,//打开弹窗的对应下标
    height:'',//屏幕高度
  },
  // 打开弹窗
  openPopup(e){
    var index = e.currentTarget.dataset.index;
    this.setData({
      showIndex:index
    })
  },
  //关闭弹窗
  closePopup(){
    this.setData({
      showIndex:null
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    var that = this;
    // 动态获取屏幕高度
    wx.getSystemInfo({
      success: (result) => {
        that.setData({
          height: result.windowHeight
        });
      },
    })
  },
})

代码简洁,类型齐全。本人才疏学浅,代码仅供参考,如有问题,请多多指教,酸Q。文章来源地址https://www.toymoban.com/news/detail-504941.html

到了这里,关于微信小程序弹窗的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 微信小程序首页、界面布局、自定义顶部(示例一)

    具体界面见下图: 如需界面中引用的图片文件和更多功能,请滑动至底部查看下载链接,可下载完整版,下载后直接使用微信开发者工具打开即可,完整版功能更详细呦。当前界面的布局样式代码如下(如存在不足之处,请根据具体需求,自行修改): 1、js代码: 2、wxml代

    2024年02月12日
    浏览(30)
  • 微信小程序自定义顶部状态栏滑动显示标题居中

    开启了自定义顶部的配置,轮播图覆盖了顶部,所以需要做一个上滑到胶囊后重新把标题重新展示出来的操作,自定义标题出现不居中情况,以下为解决后的方案,复制粘贴即可: . wxml: . . wxss: . . 滑动事件:滑动到胶囊后把标题展示出来 . . 计算胶囊按钮高度、状态栏高

    2024年02月17日
    浏览(39)
  • 微信小程序自定义底部导航栏

    微信小程序自定义底部导航栏,原生实现,不包含其他任何第三方组件,比较干净,开箱即用 效果预览: 可自定义底部导航栏列表样式 可自定义每个菜单的默认、激活后的图标和文字样式 可自定义是否添加中间的大图标菜单,当然也可自定义大图标的默认与激活样式 可自

    2024年02月07日
    浏览(43)
  • 微信小程序——自定义底部tabBar

    目录  实现步骤 1、配置信息 2、添加代码文件。  3、在该目录下编写代码即可。 二、在app.json里面添加tabBar配置 三.、在custom-tab-bar添加配置 1. 在custom-tab-bar创建如下目录 2.给index.wxml添加tabBar的结构代码   3. 给index.js 添加数据配置 和 事件方法 4. 给index.wxss 添加样式 四、

    2024年02月16日
    浏览(40)
  • 微信小程序底部tabbar自定义 实现凸起+透明底部效果

    先上图看效果: 步骤: 1、在文件根目录下创建一个文件夹:custom-tab-bar并分别创建 (js,json,wxml,wxss)类型文件 2、在pages.json中设置tabbar中的custom为true(true自定义,false默认系统) 3、index.js代码如下:

    2024年02月09日
    浏览(44)
  • 【微信小程序】底部弹窗固定定位fixed+textarea,导致的adjust-position在安卓手机失效问题

    安卓手机测试时候发现,fixed固定定位导致键盘弹出时,textarea无法正常被顶上去。 然后我就尝试了第二种方法用scroll-view将高度设置为100vh时,将页面保持在视口高度,这个时候发现不管是弹窗是fixed还是absolute都无法让安卓手机的键盘弹出时textarea顶上去 最后我用了最后一种

    2024年01月18日
    浏览(37)
  • 原声微信小程序自定义顶部导航栏 . 自定义navigationBar。 (单页面设置)

    本文实例为大家分享了微信小程序自定义导航栏的具体代码,供大家参考,具体内容如下 实现自定义大致需要以下?步骤: 1.在页面.JSON文件进行相关配置,以便去掉原生 备注:  navigationStyle(导航栏样式),参数: default = 默认样式,custom = 自定义样式。  2.在页面.js文件onLoad生命

    2024年02月09日
    浏览(47)
  • 微信小程序自定义 底部 tabbar (中间凸起)

    在与 pages 文件夹同级的地方新建 custom-tab-bar 文件夹,并新建 index.wxml 、index.wxss 、index.js 、index.json 四个文件夹 注意路径!!! 复制后会报错,把图片和页面路径改掉就好了!!! 提示: 不要无脑复制,复制到自己的项目中后记得更改图片、页面路径!!! 如需自定义 头

    2024年02月20日
    浏览(37)
  • 微信小程序|自定义弹窗组件

    2024年02月12日
    浏览(29)
  • 微信小程序自定义底部菜单设计,固定在底部,并非使用tabBar设计

    1.微信小程序自定义底部菜单设计,并且固定在底部,并非tabBar设计 场景:比如加载详情页时:底部需要加入购物车、收藏、返回主页等设计 效果图: 点击事件发生 xx.wxml 样式设计xx.wxss js设计xx.js

    2024年02月16日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包