html - Webapp 布局取决于设备
问题描述
嗨,我是编程新手,我正在尝试使用 Polymer3 构建一个渐进式 Web 应用程序,我想在桌面中打开它时以特定布局显示 Web 应用程序,并且我想以不同方式显示 Web 应用程序我在移动设备中使用它。我不知道我该怎么做,有人可以把我送到正确的方向,这样我就可以解除封锁吗?
任何帮助都非常感谢。
解决方案
如果由于设备类型而需要两种不同的布局,下面的代码可能会对您有所帮助:
static get template() {return `
<template is='dom-if' if='[[mobileDevice]]'>
.... Mobile device Layout
</template>
<template is='dom-if' if='[[!mobileDevice]]'>
.... Desktop device Layout
</template>'
...
//
ready(){
super.ready()
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
// Mobile device
this.set('mobileDevice', true);
} else {
// Desktop
this.set('mobileDevice', false);
}
}
推荐阅读
- android - 如何在环境中设置 ANT_ROOT?
- speech-to-text - 语音转文本号码捕获
- c++ - 为什么我不能通过这个函数?C++
- javascript - WordPress - functions.php 不会注册我的 JavaScript 文件
- javascript - 如何屏蔽除最后一位以外的所有内容
- grapesjs - 同一页面上可以有多个grapesjs实例吗?
- python - 创建一个函数来自动化 SQL 连接
- c# - 动画按钮从一个点到另一个点
- java - Ajax:无法重定向到 AEM SLING servlet 内的内容页面
- arrays - 如何在数组中查找重复项的索引