function adapter(callback) {
var style = document.createElement("style");
var zWidth = 750;
var zHeight = 1206;
let innerWidth = Math.min(window.innerWidth, 750);
var bjZoom = Math.max(innerWidth / zWidth, window.innerHeight / zHeight);
var contentZoom = Math.min(innerWidth / zWidth, window.innerHeight / zHeight);
var x1 = ((innerWidth - zWidth * bjZoom) / 2).toFixed(2);
var y1 = ((window.innerHeight - zHeight * bjZoom) / 2).toFixed(2);
var x2 = ((innerWidth - zWidth * contentZoom) / 2).toFixed(2);
var y2 = ((window.innerHeight - zHeight * contentZoom) / 2).toFixed(2);
var containerStyles = `
html, body{
transform-origin: 0% 0%;
-webkit-transform-origin: 0% 0%;
position: absolute;
width: ${window.innerWidth}px;
height: ${window.innerHeight}px;
overflow: hidden;
}
.page, .container{
transform-origin: 0% 0%;
-webkit-transform-origin: 0% 0%;
position: absolute;
left: 0;
right: 0;
width: ${innerWidth}px;
height: ${window.innerHeight}px;
overflow: hidden;
margin: auto;
}
`;
// 容器相关的样式
var pageStyles = `
.bg, .content, .scroll-view{
transform-origin: 0% 0%;
-webkit-transform-origin: 0% 0%;
position: absolute;
width: ${zWidth}px;
height: ${zHeight}px;
}
`;
// 背景相关的样式
var bgStyles = `
.bg{
transform: translate(${x1}px, ${y1}px) scale(${bjZoom});
-webkit-transform: translate(${x1}px, ${y1}px) scale(${bjZoom});
}
`;
// 内容相关的样式
var contentStyles = `
.content{
transform: translate(${x2}px, ${y2}px) scale(${contentZoom});
-webkit-transform: translate(${x2}px, ${y2}px) scale(${contentZoom});
}
`;
// 自定义缩放相关的样式
var zoomStyles = `
.defineZoom{
zoom: ${contentZoom};
}
`;
// 内容相关的样式
var zoomWidth = innerWidth / zWidth;
var scrollviewStyles = `
.scroll-view{
transform: scale(${zoomWidth});
-webkit-transform: scale(${zoomWidth});
width: ${innerWidth / zoomWidth}px;
height: ${window.innerHeight / zoomWidth}px;
overflow: auto;
}
`;
style.textContent = (
containerStyles +
pageStyles +
bgStyles +
contentStyles +
scrollviewStyles +
zoomStyles
).replace(/\n/g, "");
document.head.appendChild(style);
// 适配完成
if (typeof callback == "function") {
callback();
}
}
export default adapter;
移动端+pc端自适应适配解决方案
版权申诉
5星 · 超过95%的资源 129 浏览量
2022-06-29
16:26:38
上传
评论 4
收藏 945B ZIP 举报
一个喜欢玩胶的码农
- 粉丝: 10
- 资源: 6
最新资源
- 王姿.html
- 51单片机学习(1)-软件keil下载
- 历届(第1-21届)希望杯数学竞赛初一试题及答案(最新整理).doc全国数学邀请赛(264页资料)
- 水滴.psd
- TokenPocket_V2.1.2_release.apk
- Apache-druid-kafka-rce.yaml
- 基于C#的ASP.NET数据库原理及应用技术课程指导平台的开发
- 基于ROS的智能车轨迹跟踪算法的仿真与设计源码运用PID跟踪算法.zip.zip
- Bug Bounty Tip - i春秋Self-XSS变废为宝的奇思妙想
- 1991-2015年全国初中化学竞赛复赛试题汇编(212页)(24年竞赛复赛真题).docx天原杯
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页