缩放布局
This commit is contained in:
28
src/App.vue
28
src/App.vue
@@ -2,7 +2,7 @@
|
|||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<apps-nav/>
|
<apps-nav/>
|
||||||
<router-view class="components"/>
|
<router-view class="components fill"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -21,6 +21,7 @@ html, body, #app {
|
|||||||
|
|
||||||
.components {
|
.components {
|
||||||
background: #07193D;
|
background: #07193D;
|
||||||
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
@@ -29,5 +30,30 @@ import AppsNav from "@/components/appsNav.vue";
|
|||||||
export default {
|
export default {
|
||||||
name: "App",
|
name: "App",
|
||||||
components: {AppsNav},
|
components: {AppsNav},
|
||||||
|
methods: {
|
||||||
|
scaleByAspect() {
|
||||||
|
const targetWidth = 1920;
|
||||||
|
const targetHeight = 1080;
|
||||||
|
const ratio = targetWidth / targetHeight;
|
||||||
|
const element = this.$el.querySelector('.components');
|
||||||
|
const {width: originalWidth, height: originalHeight} = element.getBoundingClientRect();
|
||||||
|
const ratioHeight = originalWidth / ratio;
|
||||||
|
let scale
|
||||||
|
if (ratioHeight < originalHeight) {
|
||||||
|
scale = originalWidth / targetWidth;
|
||||||
|
} else {
|
||||||
|
scale = originalHeight / targetHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
element.style.transform = `scale(${scale})`;
|
||||||
|
element.style.width = '1920px'
|
||||||
|
element.style.height = '1080px'
|
||||||
|
element.style.transformOrigin = 'top center';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.scaleByAspect()
|
||||||
|
window.onresize = () => this.scaleByAspect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: "appsNav",
|
name: "appsNav",
|
||||||
|
props: {
|
||||||
|
width: {default: "200px"}
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
menu: []
|
menu: []
|
||||||
@@ -13,14 +16,14 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="appsNav">
|
<div class="appsNav" :style="{width}">
|
||||||
<img src="../assets/logo.svg" class="logo"/>
|
<img src="../assets/logo.svg" class="logo"/>
|
||||||
<div class="item pointer" v-for="item in menu" :key="item.name" v-text="item.label" @click="$router.push({name: item.name})"/>
|
<div class="item pointer" v-for="item in menu" :key="item.name" v-text="item.label" @click="$router.push({name: item.name})"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.appsNav {
|
.appsNav {
|
||||||
width: 200px;
|
flex-shrink: 0;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
background: #f3f6f9;
|
background: #f3f6f9;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user