仿了潮汐睡眠小程序的代码。【如果有侵权联系删除

最近做的项目有个弹出层效果,类似音乐播放器那种。按照普通的做了一般感觉交互不是很优雅,设计妹子把潮汐睡眠的弹层给我看了看,感觉做的挺好,于是乘着有空仿照了一下。

首先善用度娘反编译弄到了源码,但是打不开。然后自己研究源码发现他们用的是movable-view实现的。

于是仿照着搭出了基础框架。

新建了个组件

wxml
<!--components/playpanel/playpanel.wxml-->
<movable-area style="height:{{areaH}}px;" class="wrapper">
<movable-view bindchange="onPresent" bindtouchend="dragPanelEnd" bindtouchstart="dragPanelStart" class="sleep-panel-wrapper" damping="{{40}}" direction="vertical" friction="{{1}}" inertia="{{false}}" outOfBounds="{{false}}" style="padding-top:{{0}}px" x="{{0}}" y="{{sleepPanelPosition}}" class="panel"> <view class="" bindtap="presentPanel" hover-class="none" hover-stop-propagation="false">
背景内容
</view>
</movable-view>
</movable-area>
<scroll-view scroll-y style="height:400rpx" class="scroll-w" wx:if="{{showlist}}">
歌曲列表
<view id="green" class="scroll-view-item bc_green"></view>
<view id="red" class="scroll-view-item bc_red"></view>
<view id="yellow" class="scroll-view-item bc_yellow"></view>
<view id="blue" class="scroll-view-item bc_blue"></view>
</scroll-view>

歌曲列表提取出来是因为滚动组件和可拖拽的手势事件会互相影响,如果不需要弹出层有可滚动的区域可以无视。

js部分精简一下就是这样,abcd这些变量名应该是源码做了加密……appjs里还要定义一下初始数据

// components/playpanel/playpanel.js
let d = getApp();
Component({
/**
* 组件的属性列表
*/
properties: {
areaH:Number
}, /**
* 组件的初始数据
*/
data: {
sleepPanelPosition: d.globalData.screenHeight - (d.globalData.isFullScreen ? 24 : 0) - 80 / (375 / d.globalData.screenWidth),
topPosition: d.globalData.statusBarHeight + d.globalData.navBarHeight,
bottomPosition: d.globalData.screenHeight - (d.globalData.isFullScreen ? 24 : 0) - 80 / (375 / d.globalData.screenWidth),
presentProgress: 0,
disableAnimated: !1,
showlist:false,
}, /**
* 组件的方法列表
*/
methods: {
dragPanelEnd(e) { let changedTouches = e.changedTouches;
let pageY = changedTouches[0].pageY;
let topPosition = this.data.topPosition;
let bottomPosition = this.data.bottomPosition;
let distance = pageY - this.dragOrigin;
let speed = (bottomPosition - topPosition)/10; let h = 0;
h = this.data.sleepPanelPosition === topPosition ? distance > speed ? bottomPosition : topPosition : distance < -speed ?topPosition : bottomPosition,this.setData({
sleepPanelPosition: h,
showlist: h === topPosition
}); },
presentPanel() {
const {sleepPanelPosition: a, topPosition: b, bottomPosition: c} = this.data;
this.setData({
sleepPanelPosition: a === b ? c : b,
});
let showList = this.data.sleepPanelPosition === b
this.setData({
showlist: showList
})
},
dragPanelStart(a) {
const {changedTouches: b} = a;
if (b[0]) {
const {pageY: a} = b[0];
this.dragOrigin = a;
}
},
onPresent({detail: a}) {
const {y: b} = a, {topPosition: c, bottomPosition: d} = this.data, e = 1 - parseInt(1e3 * ((b - c) / (d - c))) / 1e3;
e !== this.data.presentProgress && this.setData({
presentProgress: e
}), this.data.disableAnimated || this.setData({
disableAnimated: !0
}), clearTimeout(this.recoverAnimation), this.recoverAnimation = setTimeout(() => {
this.setData({
disableAnimated: !1
}), this.recoverAnimation = null;
}, 100);
},
}
})
//app.js
```
onShow() {
wx.getSystemInfo({
success: a => {
const {
screenHeight: b,
screenWidth: c,
statusBarHeight: d
} = a;
this.globalData.isFullScreen = parseInt(100 * (c / b)) < parseInt(100 * (9 / 17)),
this.globalData.isBiggerScreen = 667 < b, this.globalData.statusBarHeight = d, this.globalData.navBarHeight = 44,
this.globalData.navBarFontSize = 18.5, this.globalData.btnScopeSize = 40, this.globalData.btnSize = 32,
this.globalData.screenHeight = b, this.globalData.screenWidth = c;
}
});
},
```

wxss部分,主要是.panel不要设置top值,其他好像没啥。

/* components/playpanel/playpanel.wxss */
.wrapper {
position: fixed;
top:;
left:;
bottom:;
right:;
width: 100vw;
height: 200vh;
pointer-events:none;
}
.panel {
width: 100%;
background: rgba(233, 233, 255, 0.8);
height: 100vh;
pointer-events: auto;
}
.scroll-view-item {
height: 300rpx;
}
.bc_green {
background: green;
}
.bc_red {
background: red;
}
.bc_yellow {
background: yellow;
}
.bc_blue {
background: blue;
}
.scroll-w {
position: fixed;
bottom:;
}

使用movable-view制作可拖拽的微信小程序弹出层效果。的更多相关文章

  1. 实现拖拽列表-微信小程序

    之前在网上搜索拖拽列表的实现时,发现了有好多的方法都是基于像素位置的计算实现的,这种方法要求列表元素的大小以及列表的位置有着非常严格的要求,修改和拓展起来非常的麻烦.于是我自己动手实现了一个基于页面元 ...

  2. 微信小程序一键生成源码 在线制作定制功能强大的微信小程序

    微信小程序发展到现在,短短的一年不到的时间(很快就要迎来微信小程序周年庆),在快迎来周年庆之际,百牛信息技术bainiu.ltd特记录一下这个发展的历程,用于将来见证小程序发展的辉煌时刻,我们还能知道 ...

  3. 微信小程序制作家庭记账本之一

    制作的第一天,思索着制作手机端APP还是微信小程序,首先是想到制作APP但是各种收费让我不得不换一条路,所以开始制作小程序,下载了微信小程序开发工具,试着学习制作方法,但是似乎没有成效,但我坚信要一步 ...

  4. 【百度地图API】如何制作可拖拽的沿道路测距

    原文:[百度地图API]如何制作可拖拽的沿道路测距 摘要: 地图测距,大家都会,不就map.getDistance麼.可是,这只能测任意两点的直线距离,用途不够实际啊.比如,我想测试北京天安门到北京后 ...

  5. 微信小程序 -- 基于 movable-view 实现拖拽排序

    微信小程序 -- 基于 movable-view 实现拖拽排序 项目基于colorui样式组件 ColorUI组件库 (color-ui.com) 1.实现效果 2. 设计思路 movable-vie ...

  6. 微信小程序如何开发制作

    微信小程序如何开发制作 微容SMO是一款微信小程序的免费在线制作工具,用户在微容平台上无需编辑代码,可通过拖拽式操作即可完成小程序的制作,真正意义上实现了小程序零代码免费制作! 消除技术门槛:无需代码 ...

  7. 微信小程序swiper制作内容高度不定的tab选项卡

    微信小程序利用swiper制作内容高度不定的tab选项卡,不使用absolute定位,不定高度,由内容自由撑开主要思路是获取内容区的高度来给swiper动态设置值 .wxml <view cla ...

  8. 微信小程序在线制作 自己制作微信小程序

    小程序是个什么东西?怎么自己制作微信小程序?微信小程序在线制作难吗?最近老是听这类问题,耳朵都长茧子了. 百牛信息技术bainiu.ltd整理发布于博客园 接下来作为一个技术人员的角度就为大家分析一下 ...

  9. 第六章 “我要点爆”微信小程序云开发实例之爆文详情页制作

    爆文详情页制作 从首页中数据列表打开相应详情页面的方法: 给数据列表中每个数据项加一个点击事件,同时将当前数据项的id暂时记录在本地,然后跳转到详情页面detail goopen: function ...

随机推荐

  1. Spring Boot集成Shiro实战

    Spring Boot集成Shiro权限验证框架,可参考: https://shiro.apache.org/spring-boot.html 引入依赖 <dependency> < ...

  2. Slow HTTP POST慢速攻击

    测试工具 模拟测试工具:slowhttptest https://github.com/shekyan/slowhttptest 安装: https://github.com/shekyan/slow ...

  3. 买不到的数目 /// 结论公式 oj26316

    题目大意: 给定a b(这题题意不清 其实a b互质) 设变量x y(x>=0,y>=0),求 x*a+y*b=c 找到最大的不可能达到的c 如a=4 b=7 那么c=14 有这样一个定理 ...

  4. WinCE下的第二个窗口程序

    MFC写的,有些简陋,但是还是感觉不错,一个小小的计算器,各个方面的功能都完成了 但是唯独那个CEdit里面的文字不能右对齐.那个扩展风格用不了

  5. java oop第07章_集合框架

    一. 什么是集合: 在Java中提供了一些可以保存同一数据类型的数据集称为集合,就是规定了一些集合的规范(接口.抽象类.实现类)及方法, 方便我们程序在保存数据时进行增.删.改.查操作,编程更加高效. ...

  6. 2019-5-21-win10-uwp-xaml-兼容多个版本条件编译

    title author date CreateTime categories win10 uwp xaml 兼容多个版本条件编译 lindexi 2019-5-21 11:19:3 +0800 20 ...

  7. vue使用CDN全局安装百度地图

    参考: https://www.zhangshengrong.com/p/O3aA7x5X4E/ 一.在public/index.html中引入cdn <script src="htt ...

  8. Python全栈开发:django网络框架(二)

    Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接数据库,并编写数据访问层代码 业务逻辑层去调用数据访问层执行 ...

  9. leetcode-157周赛-5216-统计元音字母序列的数目

    题目描述: 方法:倒推 class Solution(object): def countVowelPermutation(self, n): MOD = 10 ** 9 + 7 a=e=i=o=u= ...

  10. mysql 查询当前日期

    1.本年份 SELECT DATE_FORMAT(NOW(), '%Y'); 2.本月份(显示数字) SELECT DATE_FORMAT(NOW(), '%m'); 3.本月份(显示英文) SELE ...