项目应用-h5移动端01

1. 设备是否为竖屏还是横屏

  1. // 当前是否为 portrait 即竖屏状态,landscape 即横屏状态
  2. var mql = window.matchMedia("(orientation: portrait)");
  3. if (mql.matches){
  4. // 这里是竖屏状态
  5. }
  6. else{
  7. // 这里是横屏状态
  8. }

2. 响应式栅格系统

  1. @media (min-width:1200px){// 较大显示器}
  2. @media (min-width: 768px) and ( max-width: 767px){
  3. // 平板
  4. }
  5. @media (max-width: 767px){ //横屏的手机或者竖屏的平板 }
  6. @media (max-width: 480px){ // 竖屏的手机 }

3. 使用自定义字体

  1. @font-face {
  2. font-family: '自定义字体名';
  3. src: url('/icon/font.ttf'); // 字体文件的路径
  4. }

4. 触摸和非触摸

  1. document.documentElement.className += ('ontouchstart' in widow ) ? 'touch' : 'no-touch'

5. 解决retina屏幕,图片模糊问题(图片@2x)

  1. .icon{
  2. background-image: url('icon.png');
  3. }
  4. @media all and (max-width:320px) and (-webkit-min-device-pixel-ratio: 2){
  5. .icon{
  6. background-size: 50% 50%;
  7. }
  8. }