1. Unit (px, em, rem)
1.px: The smallest point that the screen device can physically display, points on different devices The length, width, and ratio are not necessarily the same;
2. em/rem: Similar points: both are a relative size value; different points: em is relative to the parent element, and rem is relative to html (the default value depends on the browser Depends on the browser, Chrome's default is 16px);
rem units are very popular in mobile front-end development. The rem unit does have a lot of benefits. It is relative to the root node, allowing us to unify the entire website unit. It can also make our fonts better adapt to the size of the website. However, if you have used it, you will know that it will cause a problem: when you use the Chrome browser to open the website you made, sometimes a large font will appear. Condition. But just refresh the page.
The reason why this happens is because for the convenience of calculation, we changed the original default 1rem=16px to 1rem=10px; therefore, we usually make the following settings in html:
html{
font-size:62.5%;/*10÷16×100=62.5% 1rem=10px*/
}
Copy after login
However, the Chrome browser sometimes ignores the html settings, so when initializing the page, the above font appears to be too large. If you study carefully, you will find that "elements" with too large fonts usually do not have font-size set. The font-size of the element is inherited from the root directory. Therefore, the solution is: in the parent of the text you want to display or other Set the font-size yourself; Standard, case-insensitive, HTML code:
nbsp;html><!-- 使用HTML5 DOCTYPE 不区分大小写 -->
Copy after login
2.lang: This attribute is placed in the tag to set the language type of the document (English: en; Chinese :zh, etc.), HTML code:
3.charser: declares the character encoding used in the document (GBK, UTF-8), HTML code:
4.format-detection (identification rule) → content parameter (default is yes):
Telephone: Convert numbers to dial-up links (yes/no) - no: prohibit the conversion of numbers For dial-up links, yes: enable the conversion of numbers into dial-up links;
Email: identify the email address (yes/no) - no: disable it as an email address, yes: enable the default text as an email address;
adress: Click on the address to jump to the map - no: prohibit jumping to the map, yes: enable the function of clicking on the address to jump to the map;
5.viewport (For mobile devices) →content parameters:
Width: viewport width; height: viewport height (usually not set); initial-scale: initial scaling ratio; maximum-scale: maximum scaling ratio; minimum-scale :Minimum scaling ratio; user-scalable: whether to allow scaling (yes/no)
6.SEO optimization:
Title (page title):
Keywords(page keywords):
Description(page description):< ;meta name="description" content="your description"/>
Author (webpage author):
Robots (webpage search engine indexing method): robotterms is a set of values separated by commas (,), usually the value:
none: The search engine will ignore this web page, which is equivalent to noindex, nofollow;
noindex: The search engine will not index this page; nofollow: The search engine will not continue to search other pages through the link index of this page;
all: The search engine will index this page and continue to index this page through Link index, equivalent to index, follow;
Index: Search engines index this web page; follow: Search engines continue to search other web pages through the link index of this web page;
1.H5页面窗口自动调整到设备宽度,禁止用户缩放
Copy after login
2. Ignore the recognition of the numbers on the page as phone numbers (easy to occur on ios devices)
3. Ignore the email address on the page Recognition (easy to occur on android devices)
4. Stuttering when pulling the scroll bar up and down
body{
-webkit-overflow-scrolling:touch;
overflow-scrolling:touch;
}
Copy after login
5. Disable copying, select text
body{
-webkit-user-select:none;
-moz-user-select:none;
-khtml-user-select:none;
user-select:none;
}
Copy after login
## 6. Press and hold for a long time and the page will appear Crash
html{
-webkit-touch-callout:none;
}
Copy after login
7. IOS/Android触摸元素时出现半透明灰色遮罩
html{
-webkit-tab-highlight-color:rgba(255,255,255,0);
}
Copy after login
8. 伪类 :active失效
方法一:
方法二:js给document绑定 touchstart 或 touchend 事件 document.addEventListener(‘touchstart’,function(){},false);
9. 降级处理(CSS3)
if('transition' in document.documentElement.style){
console.log(‘支持transitioin’);
}else{//这里进行降级处理,调用不同的CSS
console.log(‘不支持transition’);
}
Copy after login
10.旋转屏幕时,调整字体大小
html,body,form,fieldset,p,div,h1,h2,h3,h4,h5,h6{
-webkit-text-size-adjust:100%;
}
Copy after login
11.某些Android圆角失效
background-clip:padding-box;
Copy after login
12.IOS中input键盘事件支持不是很好(通过html5的oninput达到类似 keyup 的的效果)
document.getElementById('inputId').addEventListener('input',function(e){
var e = e || event;// 浏览器兼容性处理
var value = e.target.value;
console.log(value);
});
Copy after login
13.消除IE里面那个叉号
input:-ms-clear{
display:none;
}
Copy after login
14. IOS设备上输入框默认内阴影
html{
-webkit-appearance:none;
}
Copy after login
15.IOS设置input按钮样式会被默认样式覆盖
input,textarea{
border:0;
-webkit-appearance:none;
}
Copy after login
16. IOS键盘字母输入,默认首字母大写
17. input 类型 设置为 number 的问题:
17-1.maxlength属性用不了:<input>
function checkLength(obj,length){
if(obj.value.length > length){
obj.value = obj.value.substr(0,length);
}
}
Copy after login
17-2.设置step(默认为1):<input>
17-3.去除input默认样式
input[type=number]{
-moz-appearance:textfield;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button{
-webkit-appearance:none;
margin:0;
}
Copy after login
四.移动端事件(click点透):
1.事件的变化:
① PC端的鼠标事件(失效):mousedown、mouseup、mousemove、mouseover、mouseout、mouseenter、mouseleave
② 几个原始事件取代click点击事件(移动端click事件也存在,但会有一个200ms~300ms的触发延时问题):
touchstart→触控开始时触发,类似于mousedown
touchmove→触控点在屏幕上移动时触发,类似于mousemove
在移动设备上,触控点从一个元素移动到另一个元素上时,不会像PC端一样触发类似mouseover、mouseout、mouseenter、mouseleave等事件
touchend→触控结束时触发,类似于mouseup
touchcancel→更高级别的事情发生时触发,比如在游戏中突然来电话,就会触发touchcancel事件,并且在touchcancel时保存当前游戏的状态信息
③ PC端一台机器只有一个鼠标,与鼠标相关的属性都放到了一个event对象上;
移动端设备大多支持多点触控,一个事件可能与多个触控点相关,每个触控点都需要记录自己单独的属性,与touch相关的属性都是TouchList类型,触控位置、目标元素,全部放到了touch对象上;
touches→当前屏幕的手指列表;changedTouches→触发当前事件的手指列表;targetTouches→当前元素上的手指列表;
touch对象主要属性:
clientX / clientY→触控点相对浏览器窗口的位置;pageX / pageY→触控点相对页面的位置;screenX / screenY→触控点相对屏幕的位置;
identifier→touch对象的ID;target→当前的DOM元素 , 该属性是触控事件最先发生的元素
2.click点透事件:
① 什么是click点透 :举个例子,现有A(上)、B(下)两个盒子重叠排列,盒子A有绑定touchend事件,事件处理为隐藏盒子A,盒子B有绑定click事件,此时点击盒子A一次,也会触发到盒子B的click事件
② 点透出现的场景 :A / B两个元素层上下Z轴重叠,上层的A元素点击后消失或移开,下层的B元素有默认的click事件(如a标签),或 B元素绑定了click事件
③ 为什么会出现点透 :移动端click事件有明显的延迟,touchstart和click的区别:
touchstart:这个DOM(或冒泡到这个DOM)上手指触摸开始即能立即触发;
click: 这个DOM(或冒泡到这个DOM)上手指触摸开始,且手指未曾在屏幕上移动(某些浏览器允许移动一个非常小的位移值),
且在这个DOM上手指离开屏幕,且触摸和离开屏幕之间的间隔时间较短(某些浏览器不检测间隔时间,也会触发click)才能触发;
④ 如何解决 :
对于B元素本身没有默认click事件的情况,应统一使用touch事件,统一代码风格,并且由于click事件在移动端的延迟要大很多,不利于用户体验,所以关于触摸事件应尽量使用touch相关事件;
对于B元素本身存在默认click事件的情况,应及时取消B元素的默认点击事件,从而阻止click事件的产生,即应在 touch函数中取消事件的默认动作:
if(e.type == "touchend"){
e.preventDefault();//取消事件的默认动作(如果存在这样的动作)
}
Copy after login
好的,以上就是我从那个小的项目中获取的一些移动端的基础知识和技巧,欢迎各位看官转载或补充哦!
The above is the detailed content of Summary of basic knowledge on mobile terminals. For more information, please follow other related articles on the PHP Chinese website!