【2025年1月2日】关于腾讯云小程序平台更名为腾讯云超级应用服务的公告
控制台更新动态
Android SDK 更新动态
iOS SDK 更新动态
Flutter 更新动态
IDE 更新动态
基础库更新动态
z-index 为多少,都无法盖在原生组件上。后插入的原生组件可以覆盖之前的原生组件。<picker-view>中使用。position: fixed。overflow: hidden来裁剪原生组件的显示区域。bind:eventname的写法,只支持bindeventname。原生组件也不支持catch和capture的事件绑定方式。<video><cover-view class="controls">自定义播放控件按钮</cover-view></video>
opacity\\padding\\border-radius\\rotate\\scaleX\\scaleY\\width\\height\\left\\top\\background-color等简单样式)<wxs src="./index.wxs" module="touch" /><view class="container"><view class="videoBox"bind:touchstart="{{touch.touchstart}}"bind:touchmove="{{touch.touchmove}}"bind:touchend="{{touch.touchend}}"><video class="video-item" src="视频地址1" controls /><video class="video-item" src="视频地址2" controls /><video class="video-item" src="视频地址3" controls /></view></view>
// index.wxslet startY = 0; // 起始Y坐标let isStart = false; // 是否开始滑动let moveDistance = 0; // 移动距离let currentOffset = 0; // 保存累计偏移量// 触摸开始事件function touchstart(event, ins) {if (!isStart) {isStart = true;const touch = event.touches[0];startY = touch.pageY;}}// 触摸移动事件function touchmove(event, ins) {const { pageY } = event.touches[0];moveDistance = currentOffset + (pageY - startY);// 更新元素位置ins.selectComponent('.videoBox').setStyle({transform: `translateY(${moveDistance}px)`});}// 触摸结束事件function touchend(event, ins) {isStart = false;currentOffset = moveDistance;}module.exports = {touchstart,touchmove,touchend};
.container {width: 100vw;height: 100%;position: relative;overflow: hidden;top: 0;position: absolute;background: #000;}.videoBox {width: 100vw;height: 100%;position: absolute;}.video-item {width: 100vw;height: 100%;display: block;}
<live-pusher><cover-view class="danmu">{{danmuText}}</cover-view></live-pusher>
// utils/debounce.jsfunction debounce(fn, delay = 300, immediate = false) {let timer = null;return function (...args) {if (timer) clearTimeout(timer);if (immediate && !timer) {fn.apply(this, args); // 立即执行一次}timer = setTimeout(() => {if (!immediate) {fn.apply(this, args);}timer = null;}, delay);};}module.exports = debounce;// pages/live.jsconst debounce = require('../../utils/debounce');Page({data: { danmuText: '' },onLoad() {// 创建防抖后的更新函数,并绑定当前 Page 的 thisthis.debouncedUpdateDanmu = debounce(this.updateDanmu.bind(this), 300);},updateDanmu(text) {this.setData({ danmuText: text });}// 接收WebSocket实时消息onSocketMessage(msg) {this.debouncedUpdateDanmu(msg.content); // 高频调用会自动合并}});
cover-view仅支持嵌套cover-view和cover-image,所以弹出层中无法包含复杂交互,例如表单提交。cover-view或cover-image时易引发渲染卡顿。<view class="container"><live-pusher class="liver-pusher" url="{{pusherUrl}}" autopush="{{true}}" mode="RTC"><cover-view class="action-button" catchtap="handleOpen">打开弹出层</cover-view><cover-view class="action-button close" catchtap="handleClose">关闭弹出层</cover-view></live-pusher><view class="comments-modal" wx:if="{{open}}"><input placeholder="这是一个输入框"/></view></view>
Page({data: {open: false,},handleOpen: function () {this.setData({open: true})},handleClose: function () {this.setData({open: false})},})
.container {width: 100vw;height: 100vh;display: flex;flex-direction: column;background-color: #000;}.liver-pusher {width: 100%;flex: 1;}.action-button {position: absolute;height: 50px;line-height: 50px;text-align: center;background-color: white;}.close {left: 100px;}.comments-modal {width: 100%;background-color: #fff;height: 40vh;}
文档反馈