关于如何在微信小程序map地图上 cover-view 如何流畅展示动画

本文介绍在微信小程序开发中,如何优化地图页面上的cover-view动画,避免真机运行时出现卡顿现象。通过将动画控制从wxss转移至js,并利用微信小程序的Animation对象,实现流畅的动画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在进行微信小程序开发过程中发现了坑,map地图存在时,cover-view 所展示的动画在真机上会很卡。
解决的方法也很简单,就是不写在wxss里,而是写在js中

/*  底部弹窗开始 -使屏幕变暗  */
.commodity_screen {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: #000;
  opacity: 0.2;
  overflow: hidden;
  z-index: 99;
  color: #fff;
}
 .hua{
    width:96%;
    min-height: 500rpx;
    margin-left: 2%;
    background:#fff;
    position:absolute;
    bottom: 0rpx;
    z-index: 100;
}
 <map id="map" bindmarkertap="markertap" ></map>
 <cover-view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></cover-view>
 <cover-view class="hua" animation='{{animationData}}'   wx:if="{{showModalStatus}}"> </cover-view>

在js中运用微信小程序所编写的Animation对象
https://developers.weixin.qq.com/miniprogram/dev/api/Animation.html

	data: {
		animationData:''
	},
  //点击merkers
  markertap(e) {
    let that= this;
    wx.request({
      url: '',
      data: {
      },
      method: "post",
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        // 显示遮罩层
        var animation = wx.createAnimation({
          duration: 200,
          timingFunction: "linear",
          delay: 0
        })
        that.animation = animation
        animation.translateY(400).step()
        that.setData({
          animationData: animation.export(),
          showModalStatus: true,
        })
        setTimeout(function () {
          animation.translateY(0).step()
          that.setData({
            animationData: animation.export()
          })
        }.bind(this), 200)
      }
    })
  },

  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(400).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值