手持弹幕 字幕滚动小程序 全屏显示

标题## 手持弹幕 字幕滚动小程序

小程序能做到真正的全屏显示

很早之前看到大家都在使用字幕滚动小程序,自己也做了一款。功能还比较简单,不过已经上线了。在这里插入图片描述小程序目前有功能为:
1、字幕全屏滚动;
2、改变文字大小颜色;
3、移动速度;
4、背景颜色。

字幕文本字体改变功能还没有实现,抽时间在做做。后续会增加一些模板样式,让字体、背景样式选择更多。

让字幕滚动的关键代码:
       data: {
    animationData: {}
  },

  onReady: function() {
    const query = wx.createSelectorQuery();
    query.select('.container').boundingClientRect();
    query.select('.scroll-content').boundingClientRect();
    query.exec((res) => {
      const containerWidth = res[0].width;    //字幕文本宽度
      const contentWidth = res[1].width;       //为放文字容器宽度
      this.createAnimation(containerWidth, contentWidth);
    });
  },

  createAnimation: function(containerWidth, contentWidth) {
    const animation = wx.createAnimation({
      duration: 10000, // 动画持续时间
      timingFunction: 'linear',
      delay: 0,
      transformOrigin: '0 0 0'
    });

    const resetAnimation = wx.createAnimation({
      duration: 0, // 重置动画持续时间为 0,瞬间完成
      timingFunction: 'linear',
      delay: 0,
      transformOrigin: '0 0 0'
    });

    const animate = () => {
      // 重置位置
      resetAnimation.translateX(containerWidth).step();
      this.setData({
        animationData: resetAnimation.export()
      });

      // 确保重置动画完成后再开始滚动动画
      setTimeout(() => {
        // 滚动动画
        animation.translateX(-contentWidth).step();
        this.setData({
          animationData: animation.export()
        });

        // 在滚动动画完成后再调用animate函数
        setTimeout(animate, 10000); // 每10秒重新开始动画
      }, 50); // 50毫秒后开始滚动动画
    };

    animate(); // 初次调用animate函数,启动动画循环
   
  }
});

![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/ae60782607874702b10c6b8168b8a23b.jpeg#pic_center

![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/1acc08e423e543ffb2c2a82032e23e89.jpeg#pic_center

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值