<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style>
* {
margin: 0;
padding: 0;
}
html,body {
width: 100%;
height: 100%;
}
#app {
background: url("a.jpg") no-repeat center center;
background-size: 100% auto;
min-height: 100%;
height: 178vw;
position: relative;
background-color: #62ce94;
}
.b {
position: absolute;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translatex(-50%);
}
</style>
</head>
<body>
<div id="app">
<img src="b.png" alt="" class="b" :style="{'top': (320*index+p_y)+'px','width':180*index+'px'}">
</div>
<script src="vue.js"></script>
<script>
new Vue({
el: '#app',
data: {
index: 1,//缩放比例
p_y: 0 //手机屏幕高度过大,背景图片高度不够
},
created:function(){
let width = document.body.clientWidth;
let height = document.body.clientHeight;
if(height/width > 1068/600) {
this.p_y = (height - width/600*1068)/2
} else {
this.p_y = 0;
}
/*设置比例600*1068*/
this.index=width/375;
},
updated:function(){
}
});
</script>
</body>
</html>
效果图