解决布局跳动问题
This commit is contained in:
parent
74d299a8c3
commit
f5758abf93
@ -11,9 +11,6 @@ const { breakpoint } = useBootstrapBreakpoint();
|
|||||||
<template>
|
<template>
|
||||||
<div class="pageroot" id="examplesprocessroot">
|
<div class="pageroot" id="examplesprocessroot">
|
||||||
<div id="examplebanner" class="videorootbanner">
|
<div id="examplebanner" class="videorootbanner">
|
||||||
<!-- <img v-if="$isMobile.android.phone||$isMobile.android.tablet"-->
|
|
||||||
<!-- src="/ExpVideoPreload.png"-->
|
|
||||||
<!-- class="videoimg"/>-->
|
|
||||||
<video v-if="breakpoint==='xs'||breakpoint==='sm'||breakpoint==='md'"
|
<video v-if="breakpoint==='xs'||breakpoint==='sm'||breakpoint==='md'"
|
||||||
controls=""
|
controls=""
|
||||||
id="expbannervideo"
|
id="expbannervideo"
|
||||||
@ -23,7 +20,6 @@ const { breakpoint } = useBootstrapBreakpoint();
|
|||||||
<source :src="ExpVideo" type="video/mp4"></source>
|
<source :src="ExpVideo" type="video/mp4"></source>
|
||||||
</video>
|
</video>
|
||||||
<video v-else
|
<video v-else
|
||||||
:poster="ExpVideoPreload"
|
|
||||||
id="expbannervideo"
|
id="expbannervideo"
|
||||||
muted autoplay="autoplay"
|
muted autoplay="autoplay"
|
||||||
loop="loop" playsinline webkit-playsinline
|
loop="loop" playsinline webkit-playsinline
|
||||||
@ -52,7 +48,36 @@ const { breakpoint } = useBootstrapBreakpoint();
|
|||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
export default {
|
export default {
|
||||||
name: "Examples"
|
name: "Examples",
|
||||||
|
mounted() {
|
||||||
|
this.$nextTick(function() {
|
||||||
|
this.handleVideoLoad();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleVideoLoad: function() {
|
||||||
|
const video = document.getElementById('expbannervideo');
|
||||||
|
const container = document.getElementById('examplebanner');
|
||||||
|
|
||||||
|
if (video && container) {
|
||||||
|
// 优化:使用loadedmetadata事件,这是视频尺寸信息可用的最早时机
|
||||||
|
const handleVideoReady = () => {
|
||||||
|
container.classList.add('video-loaded');
|
||||||
|
// 移除事件监听器避免重复触发
|
||||||
|
video.removeEventListener('loadedmetadata', handleVideoReady);
|
||||||
|
video.removeEventListener('canplay', handleVideoReady);
|
||||||
|
};
|
||||||
|
|
||||||
|
video.addEventListener('loadedmetadata', handleVideoReady);
|
||||||
|
video.addEventListener('canplay', handleVideoReady);
|
||||||
|
|
||||||
|
// 如果视频已经有尺寸信息,立即触发
|
||||||
|
if (video.videoWidth > 0) {
|
||||||
|
handleVideoReady();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -19,18 +19,14 @@ const { breakpoint } = useBootstrapBreakpoint();
|
|||||||
<template>
|
<template>
|
||||||
<div id="homepageroot" class="pageroot">
|
<div id="homepageroot" class="pageroot">
|
||||||
<div id="homepagebanner" class="videorootbanner">
|
<div id="homepagebanner" class="videorootbanner">
|
||||||
<!-- <img v-if="$isMobile.android.phone||$isMobile.android.tablet"-->
|
|
||||||
<!-- src="/bannervideopreload.png"-->
|
|
||||||
<!-- class="videoimg"/>-->
|
|
||||||
<video v-if="breakpoint==='xs'||breakpoint==='sm'||breakpoint==='md'"
|
<video v-if="breakpoint==='xs'||breakpoint==='sm'||breakpoint==='md'"
|
||||||
:poster="bannervideopreload" controls=""
|
|
||||||
id="bannervideo" muted autoplay="autoplay" loop="loop"
|
id="bannervideo" muted autoplay="autoplay" loop="loop"
|
||||||
playsinline webkit-playsinline
|
playsinline webkit-playsinline
|
||||||
class="bannervideos"
|
class="bannervideos"
|
||||||
x5-video-player-type="h5-page">
|
x5-video-player-type="h5-page">
|
||||||
<source :src="HpgVideo" type="video/mp4"></source>
|
<source :src="HpgVideo" type="video/mp4"></source>
|
||||||
</video>
|
</video>
|
||||||
<video v-else :poster="bannervideopreload"
|
<video v-else
|
||||||
id="bannervideo" muted autoplay="autoplay" loop="loop"
|
id="bannervideo" muted autoplay="autoplay" loop="loop"
|
||||||
playsinline webkit-playsinline
|
playsinline webkit-playsinline
|
||||||
class="bannervideos"
|
class="bannervideos"
|
||||||
@ -179,6 +175,7 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.$nextTick(function() {
|
this.$nextTick(function() {
|
||||||
this.video_autoplay();
|
this.video_autoplay();
|
||||||
|
this.handleVideoLoad();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
@ -190,6 +187,28 @@ export default {
|
|||||||
video.play();
|
video.play();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
handleVideoLoad: function() {
|
||||||
|
const video = document.getElementById('bannervideo');
|
||||||
|
const container = document.getElementById('homepagebanner');
|
||||||
|
|
||||||
|
if (video && container) {
|
||||||
|
// 优化:使用loadedmetadata事件,这是视频尺寸信息可用的最早时机
|
||||||
|
const handleVideoReady = () => {
|
||||||
|
container.classList.add('video-loaded');
|
||||||
|
// 移除事件监听器避免重复触发
|
||||||
|
video.removeEventListener('loadedmetadata', handleVideoReady);
|
||||||
|
video.removeEventListener('canplay', handleVideoReady);
|
||||||
|
};
|
||||||
|
|
||||||
|
video.addEventListener('loadedmetadata', handleVideoReady);
|
||||||
|
video.addEventListener('canplay', handleVideoReady);
|
||||||
|
|
||||||
|
// 如果视频已经有尺寸信息,立即触发
|
||||||
|
if (video.videoWidth > 0) {
|
||||||
|
handleVideoReady();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,6 +107,9 @@ export default {
|
|||||||
@include media-breakpoint-between(xs, md) {
|
@include media-breakpoint-between(xs, md) {
|
||||||
aspect-ratio: 1.92;
|
aspect-ratio: 1.92;
|
||||||
}
|
}
|
||||||
|
@include media-breakpoint-up(md){
|
||||||
|
aspect-ratio: 2.62026969;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#blackchart{
|
#blackchart{
|
||||||
|
|||||||
@ -36,11 +36,38 @@
|
|||||||
|
|
||||||
.videorootbanner{
|
.videorootbanner{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: auto;
|
|
||||||
background-color: black;
|
background-color: black;
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 0; // 明确设置父容器z-index
|
z-index: 0;
|
||||||
overflow: hidden; // 帮助创建新的堆叠上下文
|
overflow: hidden;
|
||||||
|
|
||||||
|
// 默认状态:视频未加载时使用固定aspect-ratio
|
||||||
|
@include media-breakpoint-between(xs, md) {
|
||||||
|
aspect-ratio: 1.92;
|
||||||
|
}
|
||||||
|
@include media-breakpoint-up(md){
|
||||||
|
aspect-ratio: 2.62026969;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 视频元素默认样式
|
||||||
|
video {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当视频加载完成后,切换为自适应高度模式
|
||||||
|
&.video-loaded {
|
||||||
|
aspect-ratio: unset; // 移除固定比例
|
||||||
|
height: auto; // 高度自适应
|
||||||
|
|
||||||
|
video {
|
||||||
|
width: 100%; // 宽度占满
|
||||||
|
height: auto; // 高度自适应
|
||||||
|
object-fit: contain; // 保持视频比例,完整显示
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.bannervideos{
|
.bannervideos{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user