app左滑旋转后消失
1、左滑偏移量不足100,手指停止移动时,复位
2、左滑偏移量大于100,手指停止移动时,缓慢消失,透明度降为0
XML/HTML Code复制内容到剪贴板
- <template>
- <div class="n-full-height n-bg-primary article-answer">
- <n-navbar bgType="primary" :lefts="leftIcons" :rights="navbarRight" title="" itemIconType="inverse"
- titleType="inverse" @leftAction="navLeftAction"></n-navbar>
- <!-- @click="change" -->
- <div class="article-answer-top n-position-relative">
- <div class="top n-flex-column n-align-center">
- <div class="box1"></div>
- <div class="box2"></div>
- </div>
- <div class="article-answer-cards" ref="cards" @touchstart="touchStart" @touchmove="touchMove" @touchcancel="onAllTouchCancel" @touchend="touchEnd">
- <div class="t3"><text class="t3-text">{{asyncItem.tag}}</text></div>
- <div class="problem">
- <text class="problem-text">{{asyncItem.problem}}</text>
- </div>
- <div class="desc n-flex-row n-wrap-nowrap n-align-center">
- <text class="desc-text">{{asyncItem.attention_num}}人关注</text>
- <text class="desc-text">·</text>
- <text class="desc-text">{{asyncItem.comment_num}}人回答</text>
- </div>
- <div class="n-flex-row n-wrap-nowrap n-align-center n-position-absolute bottom-box">
- <image class="avatar" :src="asyncItem.author.avatar" mode="aspectFill"></image>
- <text class="name">{{asyncItem.author.name}}</text>
- </div>
- </div>
- </div>
- <div class="article-answer-btns n-flex-row n-wrap-nowrap n-align-center n-justify-center">
- <div class="n-flex-column n-align-center">
- <div class="article-answer-btns-box n-flex-row n-justify-center n-align-center">
- <image class="article-answer-btns-img" src="/static/img/icon-buganxingqu.png"></image>
- </div>
- <text class="article-answer-btns-text">不感兴趣</text>
- </div>
- <div class="n-flex-column n-align-center" @click="toDrawer">
- <div class="article-answer-btns-box n-flex-row n-justify-center n-align-center">
- <image class="article-answer-btns-img" src="/static/img/icon-xiehuida.png"></image>
- </div>
- <text class="article-answer-btns-text">写回答</text>
- </div>
- <div class="n-flex-column n-align-center">
- <div class="article-answer-btns-box n-flex-row n-justify-center n-align-center">
- <image class="article-answer-btns-img" src="/static/img/icon-shaohou.png"></image>
- </div>
- <text class="article-answer-btns-text">稍后答</text>
- </div>
- </div>
- <answer :title="asyncItem.title" ref="answer"></answer>
- </div>
- </template>
- <script>
- // #ifdef APP-NVUE
- const animation = uni.requireNativePlugin('animation')
- // #endif
- import { getTouchPoint } from '@/ui/utils/element.js'
- import navHelper from '@/service/navHelper.js'
- import answer from './components/answer.nvue'
- export default {
- mixins: [navHelper],
- components:{
- answer
- },
- data() {
- return {
- navbarRight: [{
- icon: '',
- text: '稍后答(10)',
- textStyle: 'font-size:28rpx;color:#FFF;',
- style: '',
- }],
- asyncItem: {
- title:"2021高考作文难吗?",
- tag: "最近83人提问过这个问题",
- problem: "关于陈红军壮烈牺牲的报道,陈红军的“发小”王煦辉这几天看了一遍又一遍,从小玩到大的伙伴如今已经天人相隔,让他至今也无法接受。在同学眼中,陈红军打小就是一位品学兼优的好子,就是这个家境贫寒的农村娃,考上了城里的高?",
- author: {
- id: 1,
- name: "一颗棒棒糖",
- avatar: "/static/avatar/1.jpg",
- },
- comment_num: 5160, // 评论数
- dig_num: 5160, // 顶数
- forward_num: 5160, // 转发数
- attention_num: 30, // 关注数
- },
- startX: 0, //滑动开始x轴位置
- startY: 0, //滑动开始y轴位置
- moveX: 0, //滑动的x轴距离
- moveY: 0, //滑动的y轴距离
- like_state:0,//-1:左滑,0:没滑动,1:右滑
- skewDeg:0,//当前滑动卡片的倾斜度
- el:null
- }
- },
- created() {
- // 操作对象
- this.$nextTick(e => {
- thisthis.el = this.$refs["cards"];
- })
- },
- methods: {
- onAllTouchCancel(e) {
- console.log("onAllTouchCancel")
- },
- toDrawer(){
- this.$refs["answer"].show()
- },
- /**
- * 触摸开始:记录位置
- * */
- touchStart (event) {
- const point = getTouchPoint(event)
- this.startX = point.x;
- this.startY = point.y;
- // console.log(this.startX,this.startY)
- },
- /**
- * 触摸开始滑动
- * */
- touchMove (event) {
- const now = getTouchPoint(event)
- var currentX = now.x;
- var currentY = now.y;
- var moveX = currentX - this.startX;
- var moveY = currentY - this.startY;
- var text = '';
- var state = 0;//-1:左滑,0:没滑动,1:右滑
- // //左右方向滑动
- if (Math.abs(moveX) > Math.abs(moveY)) {
- if (moveX < -10) {
- text = '左滑';
- state=-1;
- } else if (moveX > 10) {
- text = '右滑';
- state=1;
- }
- this.skew(moveX,moveY);
- }else {//上下方向滑动
- if (moveY < 0) text = '上滑';
- else if (moveY > 0) text = '下滑';
- }
- // console.log(text)
- this.like_state = state;
- this.moveX = moveX;
- this.moveY = moveY;
- },
- /**
- * 触摸结束
- * */
- touchEnd (event) {
- console.log(`移动距离:${Math.abs(this.moveX)}`)
- if(Math.abs(this.moveX)>100){
- this.hidden();
- }else{
- // #ifdef APP-NVUE
- animation.transition(this.el, {
- styles: {
- transform: `rotate(0px)`,
- },
- duration: 300,
- // timingFunction: 'ease-in-out',
- delay:1000
- }, () => {
- // uni.showToast({
- // title: 'finished',
- // icon: 'none'
- // });
- })
- // #endif
- }
- },
- /**
- * 触摸结束,卡片消失
- * */
- hidden (){
- var anim = {
- duration: 400,
- timingFunction: 'ease-in-out'
- };
- if(this.like_state==-1){
- anim.transform = 'translate(-400px, -400px)'
- }else if(this.like_state==1){
- anim.transform = 'translate(400px, -400px)'
- }
- // #ifdef APP-NVUE
- console.log(anim)
- animation.transition(this.el, anim, () => {
- // uni.showToast({
- // title: 'finished',
- // icon: 'none'
- // });
- animation.transition(this.el, {
- styles: {
- transform: `rotate(${this.skewDeg}px)`,
- opacity:0
- },
- duration: 500,
- delay:1000
- }, () => {
- // uni.showToast({
- // title: 'finished',
- // icon: 'none'
- // });
- })
- })
- // #endif
- },
- /**
- * 触摸卡片倾斜
- * */
- skew (moveX,moveY){
- let that = this;
- if(Math.abs(moveX)<180){
- //console.log(`角度:${this.skewDeg}`)
- this.skewDeg = moveX / 4; // 旋转
- // console.log("skewDeg",this.skewDeg)
- // #ifdef APP-NVUE
- animation.transition(this.el, {
- styles: {
- transform: `rotate(${this.skewDeg}px)`,
- },
- duration: 500,
- timingFunction: 'linear',
- delay:1000
- }, () => {
- // uni.showToast({
- // title: 'finished',
- // icon: 'none'
- // });
- })
- // #endif
- }
- },
- }
- }
- </script>
- <style lang="scss">
- page {
- background-color: #477FE7;
- }
- .article-answer {
- &-top {
- margin-top: 100rpx;
- .box1,
- .box2 {
- background: #BBD2FC;
- box-shadow: 0px 2rpx 30rpx 0px rgba(94, 114, 153, 0.3);
- border-top-left-radius: 30rpx;
- border-top-right-radius: 30rpx;
- height: 25rpx;
- }
- .box1 {
- width: 560rpx;
- }
- .box2 {
- width: 620rpx;
- height: 815rpx;
- border-bottom-left-radius: 30rpx;
- border-bottom-right-radius: 30rpx;
- }
- }
- .article-answer-cards {
- position: absolute;
- top: 50rpx;
- width: 690rpx;
- margin-left: 30rpx;
- background: #FFFFFF;
- height: 795rpx;
- box-shadow: 0px 2rpx 30rpx 0px rgba(94, 114, 153, 0.3);
- border-radius: 30rpx;
- // overflow:hidden;
- padding: 30rpx;
- /* #ifndef APP-NVUE */
- box-sizing: border-box;
- /* #endif */
- }
- .t3 {
- padding: 0 0 25rpx 0;
- .t3-text {
- font-size: 26rpx;
- background-color: #ECECEC;
- padding: 8rpx 18rpx;
- color: #999999;
- border-radius: 10rpx;
- }
- }
- .problem {
- height: 180rpx;
- overflow: hidden;
- text-overflow: ellipsis;
- .problem-text {
- font-size: 32rpx;
- color: #333333;
- line-height: 46rpx;
- }
- }
- .desc {
- margin-top: 36rpx;
- .desc-text {
- font-size: 26rpx;
- color: #999999;
- }
- }
- .bottom-box {
- bottom: 30rpx;
- left: 30rpx;
- .avatar {
- width: 80rpx;
- height: 80rpx;
- border-radius: 50%;
- margin-right: 20rpx;
- }
- .name {
- font-size: 28rpx;
- color: #AAAAAA;
- }
- }
- }
- .article-answer-btns {
- margin-top: 55rpx;
- &-box {
- width: 150rpx;
- height: 150rpx;
- background: #FFFFFF;
- box-shadow: 0px 2rpx 30rpx 0px rgba(94, 114, 153, 0.3);
- border-radius: 50%;
- margin: 0 30rpx;
- }
- &-img {
- width: 74rpx;
- height: 74rpx;
- }
- &-text {
- font-size: 30rpx;
- color: #FFFFFF;
- margin-top: 18rpx;
- }
- }
- }
- </style>
下一篇 仿知乎叠加卡片动画切换效果