149人参与 • 2024-08-02 • uniapp
// videozindex1-coverview.vue页面
<video src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4"
style="width: 100%;position: relative;">
<cover-view class="cover-box">
<cover-view>覆盖的内容</cover-view>
</cover-view>
</video>
// 样式
<style lang="less" scoped>
.cover-box {
position: fixed;
bottom: 0;
width: 100%;
height: 120rpx;
background-color: yellow;
}
</style>
只能子绝父相覆盖视频,fixed固定定位仍然不能覆盖视频,不符合我的需求
// videozindex2-plus.vue页面
<script>
export default {
data() {
return {
optionview: null
}
},
onload() {
// 这里我的高度统一是120rpx,但是plus不能用rpx,所以需要算一下
let rpxunit = 1
uni.getsysteminfo({
success: (info) => {
rpxunit = info.screenwidth / 750
}
});
this.optionview = new plus.nativeobj.view("option-view", {
position: "dock",
dock: "bottom",
width: "100%",
height: `${rpxunit*120}px`,
bottom: 0,
backgroundcolor: "#fff",
}, [{
id: "rect-id",
tag: "rect",
color: "#f98d2b",
position: {
top: `${rpxunit*20}px`,
bottom: `${rpxunit*20}px`,
left: `${rpxunit*225}px`,
right: `${rpxunit*225}px`,
},
rectstyles: {
radius: `${rpxunit*40}px`
}
}, {
id: 'font-id',
tag: 'font',
text: '操作',
position: {
top: `${rpxunit*20}px`,
bottom: `${rpxunit*20}px`,
left: `${rpxunit*225}px`,
right: `${rpxunit*225}px`,
},
textstyles: {
align: "center",
color: "#fff",
size: '18px'
}
}]);
this.optionview.show()
},
onunload(){
this.optionview.close()
},
methods: {
}
}
</script>
这里我需要一直显示,在页面加载的时候就显示,实际上这个子窗体可以在任何时机显示和隐藏。
onload() {
const subnvue = uni.getsubnvuebyid("bottom-fixed-operation-box")
subnvue.show("none", 0, () => {})
},
// operation.nvue子窗体页面
<template>
<view class="operation-box">
<button class="btn-self" @click="operationfun">
<text class="font-box">操作</text>
</button>
</view>
</template>
<script>
export default {
onload() {
uni.$on("back",(e)=>{
console.log("监听页面事件",e);
})
},
methods: {
operationfun(){
console.log("点击");
uni.$emit('bottom-fixed-operation-box',"参数")
}
}
}
</script>
<style scoped>
.operation-box {
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
width: 749rpx;
height: 119rpx;
background-color: #fff;
}
.btn-self {
width: 300rpx;
height: 80rpx;
background-color: #f98d2b;
border-radius: 50px;
margin: 0;
}
.font-box {
color: #fff;
font-size: 28rpx;
line-height: 80rpx;
}
</style>
// videozindex3-subnvue.vue 使用子窗体的页面
<template>
<view style="padding: 0 50rpx;">
<view v-for="item in 10" :key="item" style="height: 100rpx;background-color: pink;">
其它内容
</view>
<video src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4" style="width: 100%;"></video>
<view v-for="item in 5" :key="item" style="height: 100rpx;background-color: pink;">
其它内容
</view>
</view>
<!-- <view class="seat"> </view>
<view class="button-box">
<button class="btn-self">操作</button>
</view> -->
</template>
<script>
export default {
data() {
return {
}
},
onload() {
const subnvue = uni.getsubnvuebyid("bottom-fixed-operation-box")
subnvue.show("none", 0, () => {})
uni.$on("bottom-fixed-operation-box", (e) => {
console.log("参数",e);
this.operationfun()
})
},
mounted() {
uni.$emit("back","发送给子窗体的参数")
},
methods: {
operationfun() {
console.log("页面获取到了子窗体的点击事件,继续其它操作。");
}
}
}
</script>
<style lang="less" scoped>
.seat {
height: 120rpx;
}
.button-box {
display: flex;
justify-content: space-around;
position: fixed;
bottom: 0;
width: 100%;
color: #666;
font-size: 28rpx;
background-color: #fff;
background-color: yellow;
padding: 20rpx 40rpx;
box-shadow: 1px 2px 30px rgba(0, 0, 0, 0.2);
box-sizing: border-box;
z-index: 10;
.btn-self {
width: 40%;
height: 80rpx;
color: #fff;
font-size: 28rpx;
line-height: 80rpx;
background-color: #f98d2b;
border-radius: 50px;
margin: 0;
}
}
</style>
发送:
uni.$emit('bottom-fixed-operation-box',"参数")
接收:
uni.$on("bottom-fixed-operation-box", (e) => {
console.log("参数",e);
// 响应后的其它操作
})
uni.$on("your-event")
和uni.$off("your-event")
需要搭配使用,否则再次进入页面时,触发事件时会多次执行$on
里的操作。// 举例:
uni.$on("bottom-fixed-operation-box", (e) => {
uni.navigateto({
url: '/pages/...'
})
})
// 结果:多次进入页面时候触发此事件会进行多次页面跳转
onload()
里的uni.$on
似乎比其它代码都优先执行,uni.$off
也不生效,重复进入页面仍会多次接收uni.$emit
的触发事件,无法实现动态交互。您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论