热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

微信小程序如何实现底部弹出框封装

这篇“微信小程序如何实现底部弹出框封装”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴

这篇“微信小程序如何实现底部弹出框封装”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“微信小程序如何实现底部弹出框封装”文章吧。

微信小程序如何实现底部弹出框封装

微信小程序如何实现底部弹出框封装


  点击唤起弹窗222

  
  
{
  "usingComponents": {
    "dialogA":"/components/dialogA/dialog",
    "dialog":"/components/dialog/dialog"
  }
}
// index.js
// 获取应用实例
const app = getApp()

Page({

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        this.popup = this.selectComponent("#dialog"); //获取
    },
    
    
    // 调用子组件事件---弹窗2
    changeRange2(e) {
        var _this = this;
        _this.popup.changeRange(); //调用子组件内的函数

    },
    
})

微信小程序如何实现底部弹出框封装



    
    
    
    
        
            
                商品类型
                
                    
                
            
            
                
                    {{item}}
                
                
                    确认
                
            

        
    
/* components/dialog/dialog.wxss */
/*模态框*/
/*使屏幕变暗  */
.background_screen {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: #000;
  opacity: 0.2;
  overflow: hidden;
  z-index: 1000;
  color: #fff;
}

/*对话框 */
.attr_box {
  background: #FFFFFF;
  opacity: 1;
  /* border-radius: 0px 0px 0px 0px; */
  /* height: 500rpx; */
  height: auto;
  width: 100%;
  overflow: hidden;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 2000;
  background: #fff;
  /* background: rgba(66, 66, 66, .6); */
  padding-top: 40rpx;
  padding-bottom: 90rpx;
  box-sizing: border-box;

}


.dialog-box {
  width: 100%;
  height: 100%;
  /* background-color: pink; */
}

.dialog-head {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 60rpx;
  /* background-color: rgb(215, 255, 192); */
}

.dialog-title {
  width: 80%;
  height: 100%;
  font-size: 32rpx;
  font-family: PingFang SC;
  font-weight: bold;
  /* line-height: 40rpx; */
  color: rgba(0, 0, 0, .9);
  /* background-color: rgb(255, 254, 192); */

  display: flex;
  align-items: center;
  justify-content: center;
}

.close2ImgBox {
  width: 10%;
  height: 100%;
  display: flex;
  align-items: center;
}

.close2Img {
  width: 44rpx;
  height: 44rpx;
}

.dialog-content {
  height: calc(100% - 60rpx);
  /* background-color: rgb(192, 237, 255); */
  box-sizing: border-box;
  padding: 40rpx 0;
}

/* 主体内容 */
.select-box {
  /* background-color: rgb(240, 230, 146); */
  display: flex;
  flex-wrap: wrap;
  justify-content: start;
  box-sizing: border-box;
  padding: 10rpx;
  padding: 0 0 30rpx 0rpx;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.select-item {
  width: 80%;
  height: 88rpx;
  line-height: 68rpx;
  background: #f6f5f8;
  opacity: 1;
  border-radius: 40rpx;
  text-align: center;
  font-size: 32rpx;
  font-family: PingFang SC;
  font-weight: 400;
  color: #151521;
  /* margin-right: 10rpx; */
  margin-bottom: 32rpx;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
}

.selectedItem {
  background: #ff5050;
  color: #fff;
  border: 1px solid #ff5050;
}

.btnBox {
  width: 100%;
  /* height: auto; */
  display: flex;
  justify-content: center;
  align-items: center;
}

.btn {
  width: 90% !important;
  height: 88rpx;
  background: #FF3B3B;
  opacity: 1;
  font-size: 32rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #FFFFFF;
  opacity: 1;
  border-radius: 48rpx;
  border: none;
  outline: none;
  position: absolute;
  bottom: 50rpx;
  left: 50%;
  transform: translate(-50%, 0);
  display: flex;
  justify-content: center;
  align-items: center;
}
// // components/dialog/dialog.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {},

    /**
     * 组件的初始数据
     */
    data: {
        //弹窗显示控制
        showModalStatus: false,
        // isShowDialog: false, //是否显示提示控件组件

        // 点击添加的数据
        tabData: {
            // title: '拒绝发货',
            val: ['库存', '跨境现货', '爆款', '新品'],
            toValIndex: null,
        }, //需要传递的值
    },
    /**
     * 组件的方法列表
     */
    methods: {
        //点击显示底部弹出
        changeRange: function () {
            this.showModal();
            console.log('我是弹窗打开----');
        },

        //底部弹出框
        showModal: function () {
            // 背景遮罩层
            var animation = wx.createAnimation({
                duration: 50,
                timingFunction: "linear",
                delay: 0
            })
            //this.animation = animation
            animation.translateY(50).step()
            this.setData({
                animationData: animation.export(),
                showModalStatus: true
            })
            setTimeout(function () {
                animation.translateY(0).step()
                this.setData({
                    animationData: animation.export()
                })
            }.bind(this), 50)
        },

        //点击背景面任意一处时,弹出框隐藏
        hideModal: function (e) {
            //弹出框消失动画
            var animation = wx.createAnimation({
                duration: 10,
                timingFunction: "linear",
                delay: 0
            })
            //this.animation = animation
            animation.translateY(10).step()
            this.setData({
                animationData: animation.export(),
            })
            setTimeout(function () {
                animation.translateY(0).step()
                this.setData({
                    animationData: animation.export(),
                    showModalStatus: false
                })
            }.bind(this), 10)
        },

        // 选择选项-----弹出框选择添加类型
        getValueTap(e) {
            console.log(e);
            let dialogid = e.currentTarget.dataset.dialogid;
            console.log(dialogid);
            this.setData({
                ['tabData.toValIndex']: dialogid, //更新
            })
            // var toNum = this.data.tabData.index;
        },
    },
    // 生命周期
    lifetimes: {
        ready: function () {

        },
    }
})

以上就是关于“微信小程序如何实现底部弹出框封装”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注编程笔记行业资讯频道。


推荐阅读
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • vue使用
    关键词: ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • 微信小程序导航跟随的实现方法
    本文介绍了在微信小程序中实现导航跟随的方法。通过设置导航的position属性和绑定滚动事件,可以实现页面向下滚动到导航位置时,导航固定在页面最上方;页面向上滚动到导航位置时,导航恢复到原始位置;点击导航可以平滑跳转到相应位置。代码示例也给出了具体实现方法。 ... [详细]
  • 抽空写了一个ICON图标的转换程序
    抽空写了一个ICON图标的转换程序,支持png\jpe\bmp格式到ico的转换。具体的程序就在下面,如果看的人多,过两天再把思路写一下。 ... [详细]
  • 本篇文章笔者在上海吃饭的时候突然想到的这段时间就有想写几篇关于返回系统的笔记,所以回家到之后就奋笔疾书的写出来发布了事先在网上找了很多方法,发现有 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文详细介绍了MySQL表分区的创建、增加和删除方法,包括查看分区数据量和全库数据量的方法。欢迎大家阅读并给予点评。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 超级简单加解密工具的方案和功能
    本文介绍了一个超级简单的加解密工具的方案和功能。该工具可以读取文件头,并根据特定长度进行加密,加密后将加密部分写入源文件。同时,该工具也支持解密操作。加密和解密过程是可逆的。本文还提到了一些相关的功能和使用方法,并给出了Python代码示例。 ... [详细]
  • Android源码中的Builder模式及其作用
    本文主要解释了什么是Builder模式以及其作用,并结合Android源码来分析Builder模式的实现。Builder模式是将产品的设计、表示和构建进行分离,通过引入建造者角色,简化了构建复杂产品的流程,并且使得产品的构建可以灵活适应变化。使用Builder模式可以解决开发者需要关注产品表示和构建步骤的问题,并且当构建流程发生变化时,无需修改代码即可适配新的构建流程。 ... [详细]
author-avatar
快乐的芙蓉HAPPY
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有