• 小程序淡入淡出效果-初步想法,有好的想法在贴出来


    wxml

    <view class='bg' style='background-size: 100% {{winHeight}}px;'>
    <!-- 背景 -->
    <scroll-view class='scroll' style='height:{{winHeight}}px' scroll-y upper-threshold bindscrolltoupper='scrolltoupper' animation="{{animationData}}" hidden='{{!hidden}}'>
    </scroll-view>
    <scroll-view class='scroll' style='height:{{winHeight}}px' scroll-y upper-threshold bindscrolltoupper='scrolltoupper' animation="{{animationData}}" hidden='{{hidden}}'>
    <view class='top'>上边模块</view>
    <view class='kong'></view>
    <view class='top'>{{winHeight}}</view>
    <view class='top'>上边模块</view>
    <view class='top'>上边模块</view>
    </scroll-view>
    </view>
     
     
    js
     
    //xx.js
    const util = require('../../utils/util.js')
    //把winHeight设为常量,不要放在data里(一般来说不用于渲染的数据都不能放在data里)
    const winHeight = wx.getSystemInfoSync().windowHeight

    Page({
    data: {
    animationData: {},
    hidden: false,//关注默认显示
    },


    // 点击关注隐藏按钮
    bindfollow: function (e) {
    var animation = wx.createAnimation({
    duration: 1000,
    timingFunction: 'linear',
    })

    this.animation = animation

    animation.opacity(0).step()

    this.setData({
    animationData: animation.export()
    })

    setTimeout(function () {
    this.setData({
    hidden: true
    })
    }.bind(this), 1000)

    },

    onLoad: function () {
    this.setData({
    winH: wx.getSystemInfoSync().windowHeight,
    winHeight: wx.getSystemInfoSync().windowHeight,
    opacity: 1,
    //这个是微信官方给的获取logs的方法 看了收益匪浅
    logs: (wx.getStorageSync('logs') || []).map(log => {
    return util.formatTime(new Date(log))
    })
    })
    },
    onShow: function () {
    this.hide()
    },
    //核心方法,线程与setData
    hide: function () {
    var vm = this
    var interval = setInterval(function () {
    if (vm.data.winH > 0) {
    //清除interval 如果不清除interval会一直往上加
    clearInterval(interval)
    vm.setData({ winH: vm.data.winH - 5, opacity: vm.data.winH / winHeight })
    vm.hide()
    }
    }, 10);
    },
    scrolltoupper(e){
    console.log('出发了')
    this.bindfollow()
    },
    })
     
     
    wxss
     
     
    page{
    overflow: hidden;
    }
    .bg{
    100%;
    height: 100%;
    background: url('http://bmob-cdn-13048.b0.upaiyun.com/2018/09/03/6ca3930a40a4e87e806efca94d8b7808.jpg') no-repeat;
    }
    .bg view{
    100%;
    height: 400rpx;
    line-height: 400rpx;
    text-align: center;
    }
    .top,.btm1 {
    background: #fff;
    }
    .scroll{
    100%;
    height: 1000rpx;
    }

    .log-list {
    display: flex;
    flex-direction: column;
    padding: 40rpx;
    }
    .log-item {
    margin: 10rpx;
    }
    .aa{
    ">darkcyan;
    }
  • 相关阅读:
    Oracle数据类型之number
    jQuery与Dom
    Tableau问题及解决办法汇总
    安装
    impala语句
    需要模拟点击爬虫小案例
    Navicat连接Oracle报错处理
    python manage.py runserver报错
    Django安装报错
    用户行为日志
  • 原文地址:https://www.cnblogs.com/lipuqing180906/p/9711542.html
Copyright © 2020-2023  润新知