1.页面
<template>
<div class="bind_bg"></div> <!-- 这是追加的dom -->
<div class="container"></div><!-- 这是页面dom -->
</template>
2.js
setTimeout(() => {
let bg = "你的背景图片";
let bc = "你的背景颜色";
$(".bind_bg").append(`<style>.bind_bg:before{background-image: url(${bg});background-color:${bc}}</style>`);
}, 100);
3.css
.bind_bg {
background-repeat: no-repeat;
background-size: 100% 100%;
background-attachment: fixed;
position: fixed;
width: 375px;
height: 100%;
z-index: 0;
}
.bind_bg:before {
content: " ";
position: fixed;
width: 375px;
height: 100%;
z-index: 0;
bottom: 0;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-size: cover;
}