赞
踩
之前写过一篇文章
echarts——实现面积图+柱状图+折线图等——基础积累
echarts——实现面积图+柱状图+折线图等——基础积累:http://t.csdn.cn/rNmjd
里面有关于页面自适应的功能:
这个是jq
版本
$(function () { screenSize('.pageBody'); }); function screenSize(editorDom) { let screenWidth = $(window).width(); let screenHeight = $(window).height(); let defWidth = 1920; let defHeight = 1080; let xScale = screenWidth / defWidth; let yScale = screenHeight / defHeight; $(editorDom).css('transform', 'scale(' + xScale + ', ' + yScale + ')'); $(window).resize(function () { let screenWidth = $(window).width(); let screenHeight = $(window).height(); xScale = screenWidth / defWidth; yScale = screenHeight / defHeight; $(editorDom).css('transform', 'scale(' + xScale + ', ' + yScale + ')'); }); }
css部分
.pageBody {
width: 1920px;
height: 1080px;
transform-origin: 0 0 0;
overflow: hidden;
padding-top: 80px;
}
如果是vue
版本,则需要用下面的方式来处理
jq
插件npm install jquery --save
vue.config.js
中加入以下内容——chainWebpack
在chainWebpack
中加入下面的内容
chainWebpack:(config)=>{
config.plugin('provide').use(webpack.ProvidePlugin, [
{
$: 'jquery',
jquery: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
},
]);
}
import $ from 'jquery';
screenSize(editorDom) { let screenWidth = $(window).width(); let screenHeight = $(window).height(); let defWidth = 1920; let defHeight = 940; let xScale = screenWidth / defWidth; let yScale = screenHeight / defHeight; $(editorDom).css('transform', 'scale(' + xScale + ', ' + yScale + ')'); $(window).resize(() => { let screenWidth = $(window).width(); let screenHeight = $(window).height(); xScale = screenWidth / defWidth; yScale = screenHeight / defHeight; $(editorDom).css('transform', 'scale(' + xScale + ', ' + yScale + ')'); }); },
mounted() {
this.screenSize('.pageBody');
},
html
代码<template>
<div style="height: 100vh; overflow: hidden">
<div class="pageBody newPageBody">
//页面内容
</div>
</div>
</template>
.pageBody {
width: 1920px;
height: 1080px;
transform-origin: 0 0 0;
overflow: hidden;
padding-top: 80px;
}
完成!!!多多积累,多多收获!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。