这是H5项目完成后的一些整理,有些理解不能非常准确,希望大家能帮忙指出。

移动端的适配


一些名词解释

  • visual viewport 可视视图
  • layout viewport 布局视图
  • vm 可视视图的宽度,最大为100.类似一个百分比的值
  • vh 可视视图的高度
  • points 独立像素点。抽象的单位,在数学的坐标空间才有意义
  • dpr = 物理像素/独立像素点。
  • display zoom 在苹果设置中显示有 标准和 放大。
  • rendered Pixels = points*dpr
  • physical pixels 物理像素,在display zoom 模式下 设备的分辨率可能会更低。
  • PPI 每英寸上的像素个数。这里的像素是 rendered pixels 逻辑像素。
  • DIPs or dp device independent pixel 设备无关的独立像素,比如css 的px单位



图片来源 githubusercontent

我们采用的是淘宝的 lib-flexible 方案,该方案的总体思路为模拟vm和vh。

比如750*1334的设计图 通过插件webpack px2rem(remUnit:75px) 来模拟vm。这样1rem就等于1vm.

比如代码

.selector {
width: 150px;
height: 64px; /*px*/
font-size: 28px; /*px*/
border: 1px solid #ddd; /*no*/
}

px2rem处理后

.selector {
width: 2rem;
border: 1px solid #ddd;
}
[data-dpr="1"] .selector {
height: 32px;
font-size: 14px;
}
[data-dpr="2"] .selector {
height: 64px;
font-size: 28px;
}
[data-dpr="3"] .selector {
height: 96px;
font-size: 42px;
}

样式


  • 引用normalize.css
  • 确定变量
	/*背景色*/
$body-bg: #fff;
$component-bg:#ddd; /*常用灰色*/
$gray-darker: #222;
$gray-dark: #333;
$gray:#666;
$gray-light:#999;
$gray-lighter:#ccc;
$gray-lightest: #eee; /*主色调*/
$brand-primary: #c71628;
$brand-xxx:#ddd;//其他的颜色 /*行高*/
line-height-base: 2; // 行高/字体
line-height-large:2.4; //更高 /*字体*/
$font-size: 28px;
$font-size-large: 34px;
$font-size-small: 24px; /*... 其他项目涉及的变量*/
  • mixins

因为我平常有搜集一些不错的mixins,比如:

--buttons

生成buttons,focus、hover都对应的背景色的改变

@mixin button-variant($color, $background, $border) {
color: $color;
background-color: $background;
border-color: $border; &:focus,
&.focus {
color: $color;
background-color: darken($background, 10%);
border-color: darken($border, 25%);
}
&:hover {
color: $color;
background-color: darken($background, 10%);
border-color: darken($border, 12%);
}
&:active,
&.active{
color: $color;
background-color: darken($background, 10%);
border-color: darken($border, 12%); &:hover,
&:focus,
&.focus {
color: $color;
background-color: darken($background, 17%);
border-color: darken($border, 25%);
}
}
&:active,
&.active{
background-image: none;
}
&.disabled,
&[disabled],
fieldset[disabled] & {
&:hover,
&:focus,
&.focus {
background-color: $background;
border-color: $border;
}
}
}

--brightness

通过背景色获取字体颜色

// Brightness math based on:
// http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx $red-magic-number: 241;
$green-magic-number: 691;
$blue-magic-number: 68;
$brightness-divisor: $red-magic-number + $green-magic-number + $blue-magic-number;
@function sqrt($r) {
$x0: 1; // initial value
$solution: false; @for $i from 1 through 10 {
@if abs(2 * $x0) < 0,00000000000001 { // Don't want to divide by a number smaller than this
$solution: false;
} $x1: $x0 - ($x0 * $x0 - abs($r)) / (2 * $x0) !global; @if ( abs($x1 - $x0) / abs($x1)) < 0,0000001 { // 7 digit accuracy is desired
$solution: true;
} $x0: $x1;
} @if $solution == true {
// If $r is negative, then the output will be multiplied with <a href="http://en.wikipedia.org/wiki/Imaginary_number">i = √-1</a>
// (√xy = √x√y) => √-$r = √-1√$r
@if $r < 0 {
@return $x1 #{i};
}
@else {
@return $x1;
}
}
@else {
@return "No solution";
}
}
@function brightness($color) {
// Extract color components
$red-component: red($color);
$green-component: green($color);
$blue-component: blue($color); // Calculate a brightness value in 3d color space between 0 and 255
$number: sqrt((($red-component * $red-component * $red-magic-number) + ($green-component * $green-component * $green-magic-number) + ($blue-component * $blue-component * $blue-magic-number)) / $brightness-divisor); // Convert to percentage and return
@return $number / 255 * 100%;
} @function contrasting-color($color, $light, $dark) {
@if brightness($color) < 65% {
@return $light;
} @else {
@return $dark;
}
}

等等mixins 方便

  • 写基础的scss 代码
body{
font-size:$font-base;/*px*/ 启动post-css px2rem
color: $gray; //基础字体颜色
background: $body-bg;
}
/*字体颜色*/
.gray-darker{
color:$gray-darker;
}
.gray-dark{
color: $gray-dark;
} .gray{
color: $gray;
}
.gray-light{
color: $gray-light;
}
.gray-lighter{
color:$gray-lighter
} /*字体*/
.text-base{
font-size:$font-size;
}
.text-large{
font-size:$font-size-large
}
.text-small{
font-size:$font-size-small
}
/*按钮*/ /*helper*/
.pull-right{
float: right;
}
.pull-left{
float: left;
}
.clearfix{
@include clearfix();
}

动画


//todo 使用心得

https://daneden.github.io/animate.css/

animate.css

手势


//todo 使用心得

vue-gesture

文章引用

H5页面项目的思路整理的更多相关文章

  1. html5+css3 h5页面生成的思路

    <!DOCTYPE html><html style="height: 100%;"> <head> <meta charset=&quo ...

  2. Angular2发布思路(整理官网Deployment页面)

    本文是按着ng2官网的高级内容“Deployment”的思路整理得出的,原文虽然在angular2的中文站下挂着,截止目前却还是英文版未翻译,笔者就在这里结合自己的理解给出原文的一点点整理.这是原文地 ...

  3. vue项目引入FastClick组件解决IOS系统下h5页面中的按钮点击延迟,连续点击无反应的问题

    异常描述: ios系统手机中访问h5页面,按钮点击有延迟,连续点击卡顿.无反应. 异常原因: 这要追溯至 2007 年初.苹果公司在发布首款 iPhone 前夕,遇到一个问题:当时的网站都是为大屏幕设 ...

  4. H5打开app指定页面(H5+app项目)

    H5+app项目,在HBuilderX中设置 详情参考官方 https://ask.dcloud.net.cn/article/64 给h5+app设置scheme值,作用:在其它app和h5页面中启 ...

  5. 【原】让H5页面适配移动设备全家 - 前端篇 - PPT

    7月份在部门内给设计中心的同事们带来<让H5页面适配移动设备全家 - 设计师篇 - PPT>的分享,在视觉和交互稿上提出页面适配的建议及提升页面体验的好处,促进前端和设计双方更好的合作,同 ...

  6. 那些过目不忘的H5页面

    原文链接:http://isux.tencent.com/great-mobile-h5-pages.html 从引爆朋友圈的H5小游戏<围住神经猫>,到颠覆传统广告的大众点评H5专题页& ...

  7. 领导让我重新做一个微信H5页面!

    leader:我们需要做一个微信H5页面,效果如图,功能如描述,时间越快越好. 需求是不是很简单呢?2015-11-24 12:44:00文末有最新更新 背景描述 前几天微信转发相关项目开发后,这是第 ...

  8. 使用Flexible实现手淘H5页面的终端适配【转】

    曾几何时为了兼容IE低版本浏览器而头痛,以为到Mobile时代可以跟这些麻烦说拜拜.可没想到到了移动时代,为了处理各终端的适配而乱了手脚.对于混迹各社区的偶,时常发现大家拿手机淘宝的H5页面做讨论—— ...

  9. 使用Flexible实现手淘H5页面的终端适配(转)

    曾几何时为了兼容IE低版本浏览器而头痛,以为到Mobile时代可以跟这些麻烦说拜拜.可没想到到了移动时代,为了处理各终端的适配而乱了手脚.对于混迹各社区的偶,时常发现大家拿手机淘宝的H5页面做讨论—— ...

随机推荐

  1. 树莓派.安装Samba环境

    适用于树莓派3 树莓派装好系统后, 为了方便传文件到树莓派, 建议使用Samba这类文件夹级别的应用, 比ftp方便多了 如果你想把树莓派变成Nas, Samba也是不可或缺的应用 通过samba服务 ...

  2. Apache常用配置

    Apache配置文件:conf/httpd.conf.(注意:表示路径时使用‘/’而不使用‘\’,注释使用‘#’) 1. ServerRoot:服务器根目录,也就是Apache的安装目录,其他的目录配 ...

  3. SpringBoot初体验(续)

    1.如果你还不知道SpringBoot的厉害之处,或者你不知道SpringBoot的初级用法,请移步我的上一篇文章,传送门 2.SpringBoot中的表单验证 所谓验证,无非就是检验,对比,正如ja ...

  4. ubuntu-17.10 安装 FANN

      因为想用C语言写神经网络,不用已有的库的话,又太难了,所以准备安装一个夸平台的FANN库, 源文件下载地址http://leenissen.dk/fann/wp/download/,我下载的是最新 ...

  5. Azure ARM虚拟机部署反恶意软件-安全扩展

    Azure虚拟机,默认情况下没有安装杀毒软件.如果您有此需求可以通过Azure 扩展进行安装,有关Azure反恶意软件的官方说明请参考:https://docs.azure.cn/zh-cn/secu ...

  6. 初入WebService

    搭建webservice需要用到的jar applicationContext.xml配置文件 <?xml version="1.0" encoding="UTF- ...

  7. C语言实现二叉树的基本操作

    二叉树是一种非常重要的数据结构.本文总结了二叉树的常见操作:二叉树的构建,查找,删除,二叉树的遍历(包括前序遍历.中序遍历.后序遍历.层次遍历),二叉搜索树的构造等. 1. 二叉树的构建 二叉树的基本 ...

  8. python+selenium安装

    1.下载Python 请到官网自行下载安装https://www.python.org/downloads/ 在安装的时候,注意一定要勾上这个选项,可以免去我们配置系统变量的麻烦,如果你忘了,没关系, ...

  9. C#中split分隔字符串的应用

    .用单个字符来分隔:string str="aaajbbbjccc";string[] sArray=str.Split('j');foreach(string i in sArr ...

  10. [转载] NodeJS无所不能:细数十个令人惊讶的NodeJS开源项目

    转载自http://www.searchsoa.com.cn/showcontent_79099.htm 在几年的时间里,Node.JS逐渐发展成一个成熟的开发平台,吸引了许多开发者.有许多大型高流量 ...