H5移动和web开发

118 阅读2分钟

H5 的新特性有哪些?C3 的新特性有哪些?

一、H5 新特性

  1. 拖拽

    拖放是一种常见的特性,就是抓取对象以后拖到另一个位置 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放

  2. 音频 ,视频(audio, video) 如果浏览器不支持自动播放怎么办?在属性中添加 autoplay

  3. 画布 Canvas

  • getContext() 方法返回一个用于在画布上绘图的环境Canvas.getContext(contextID) 参数 contextID 指定了您想要在画布上绘制的类型。当前唯一的合法值是 “2d”,它指定了二维绘图,并且导致这个方法返回一个环境对象,该对象导出一个二维绘图 API
  • cxt.stroke() 如果没有这一步 线条是不会显示在画布上的
  • canvas 和 image 在处理图片的时候有什么区别?image 是通过对象的形式描述图片的,canvas 通过专门的 API 将图片绘制在画布上.
  1. 本地离线存储 localStorage 长期存储数据 浏览器关闭后数据不丢失
  2. sessionStorage 的数据在浏览器关闭后自动删除
  3. 表单控件 calendar , date , time , email , url , search , tel , file , number

CSS3 新特性

  1. 颜色: 新增 RGBA , HSLA 模式
  2. 文字阴影(text-shadow)
  3. 边框: 圆角(border-radius) 边框阴影 : box-shadow
  4. 盒子模型: box-sizing
  5. 背景:background-size background-origin background-clip
  6. 渐变: linear-gradient , radial-gradient
  7. 过渡 : transition 可实现动画
  8. 自定义动画 animate @keyfrom
  9. 媒体查询 多栏布局 @media screen and (width:800px) {…}
  10. 弹性布局 flex

二、如何使一个盒子水平垂直居中?

利用定位(常用方法,推荐)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .parent {
        width: 500px;
        height: 500px;
        border: 1px solid #000;
        position: relative;
      }
      .child {
        width: 100px;
        height: 100px;
        border: 1px solid #999;
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: -50px;
        margin-left: -50px;
      }
    </style>
  </head>
  <body>
    <div class="parent"><div class="child">我是子元素</div></div>
  </body>
</html>

利用 margin:auto

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .parent {
        width: 500px;
        height: 500px;
        border: 1px solid #000;
        position: relative;
      }
      .child {
        width: 100px;
        height: 100px;
        border: 1px solid #999;
        position: absolute;
        margin: auto;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
      }
    </style>
  </head>
  <body>
    <div class="parent"><div class="child">我是子元素</div></div>
  </body>
</html>

利用 display:table-cell

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .parent {
        width: 500px;
        height: 500px;
        border: 1px solid #000;
        display: table-cell;
        vertical-align: middle;
        text-align: center;
      }
      .child {
        width: 100px;
        height: 100px;
        border: 1px solid #999;
        display: inline-block;
      }
    </style>
  </head>
  <body>
    <div class="parent"><div class="child">我是子元素</div></div>
  </body>
</html>

利用 display:flex;设置垂直水平都居中

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .parent {
        width: 500px;
        height: 500px;
        border: 1px solid #000;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .child {
        width: 100px;
        height: 100px;
        border: 1px solid #999;
      }
    </style>
  </head>
  <body>
    <div class="parent"><div class="child">我是子元素</div></div>
  </body>
</html>

计算父盒子与子盒子的空间距离(这跟方法一是一个道理)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .parent {
        width: 500px;
        height: 500px;
        border: 1px solid #000;
      }
      .child {
        width: 100px;
        height: 100px;
        border: 1px solid #999;
        margin-top: 200px;
        margin-left: 200px;
      }
    </style>
  </head>
  <body>
    <div class="parent"><div class="child">我是子元素</div></div>
  </body>
</html>

利用 transform

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .parent {
        width: 500px;
        height: 500px;
        border: 1px solid #000;
        position: relative;
      }
      .child {
        width: 100px;
        height: 100px;
        border: 1px solid #999;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
    </style>
  </head>
  <body>
    <div class="parent"><div class="child">我是子元素</div></div>
  </body>
</html>

总结

H5和web开发的东西有很多,这一篇也没有说完。不过已经在进我努力的在总结了。总之就是作为一个页面的可视化工具H5可以说是有很多很好的东西值得我们学习,希望我们在平时工作也好干什么也好不要忘记了我们曾经学过的H5和web开发的基础。

最后立个flag吧!以后每周都会写一篇博客,不说一下子跳到了一个新高度,至少也要比上一篇写的好那么一点吧,(嘿嘿)。