WEBAPP Development Summary
Contact with the development of WebKit WebApp for some time, now some of the skills to share to you:
1. Viewport:
The visible area. For the desktop browser, we all know exactly what viewport is, and that is to go out all the toolbars, the status bar, the scroll bar, and so on to look at the page area,
This is a truly effective area. Because the mobile device screen width is different from the traditional web, we need to change the viewport;
There are actually 4 properties that we can manipulate:
Width-//viewport (range from 200 to 10,000, default is 980 pixels)
Height-//viewport (range from 223 to 10,000)
Initial-scale-//Initial zoom ratio (range from >0 to 10)
Minimum-scale-//allows the user to zoom to the minimum scale
Maximum-scale-//allows the user to zoom to the maximum scale
User-scalable-//whether the user can manually shrink (no,yes)
So how do these settings make safari aware? In fact, it's very simple, just a meta, shaped like:
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">//Coding
<meta id= "viewport" name= "viewport" content= "width=320; initial-scale=1.0;maximum-scale=1.0; User-scalable=no; " />
<meta name= "apple-mobile-web-app-capable" content= "yes"/>//Another technique for offline applications
<meta name= "Apple-mobile-web-app-status-bar-style" Content=black "/>//Hide status bar
<meta content= "Black" name= "Apple-mobile-web-app-status-bar-style"/>//The style of the status bar on safari top in the specified iphone
<meta content= "Telephone=no" name= "format-detection"/>//tell the device to ignore numbers in the page as phone numbers
<meta name= "Author" contect= "mr.he"/>
After setting up the initial-scale=1, we can finally make the page design at a rate of 1:1. Another important concept about viewport is that the iphone's Safari browser has no scroll bar at all, and it's not a simple "hide scroll bar", and there is no such feature at all. The iphone's Safari browser actually displays the page completely from the beginning, and then uses viewport to see a portion of it. When you drag with your finger, you actually drag the page instead of the viewport. The browser behavior changes more than the scroll bar, and the interaction event is not the same as the normal desktop. (Please refer to: Fingertips of the next JS series article)
2. Link:
<link rel= "Apple-touch-startup-image" href= "startup.png"/>//settings Start Page picture
<link rel= "Apple-touch-icon" href= "iphon_tetris_icon.png"/>//You can display good-looking icons when setting bookmarks
<link rel= "stylesheet" media= "All and (orientation:portrait)" href= "portrait.css" >//Portrait mode style
<link rel= "stylesheet" media= "All and (Orientation:landscape)" href= "landscape.css"//Landscape mode style
Style used when vertical screen
<style media= "All and (orientation:portrait)" type= "Text/css" >
#landscape {display:none;}
</style>
Styles used when traversing a screen
<style media= "All and (Orientation:landscape)" type= "Text/css" >
#portrait {display:none;}
</style>
3. Event:
Gesture Events
Touchstart//triggers when finger touches the screen
Touchmove//triggers when a finger that has touched the screen begins to move
Touchend//triggers when the finger leaves the screen
Touchcancel
Touch events
Gesturestart//triggered when two fingers touch the screen
Gesturechange//Triggers when two fingers start moving after touching the screen
Gestureend
Screen Rotation events
Onorientationchange
Detects when a touch screen finger changes direction
Orientationchange
Related properties supported by the touch event
Touches
Targettouches
Changedtouches
ClientX//X coordinate of touch relative to the viewport (excludes scroll offset)
ClientY//Y coordinate of touch relative to the viewport (excludes scroll offset)
ScreenX//Relative to the screen
ScreenY//Relative to the screen
PageX//Relative to the full page (includes scrolling)
Pagey//Relative to the full page (includes scrolling)
Target/Node The touch event originated from
Identifier//An identifying number, unique to each touch event
4. Screen Rotation event: Onorientationchange
Add a screen rotation event to listen to the screen rotation status (left, right, or not) at any time. Example:
Determine if the screen is rotated
function Orientationchange () {
Switch (window.orientation) {
Case 0:
Alert ("Portrait mode 0,screen-width:" + Screen.width + "; Screen-height: "+ screen.height);
Break
CASE-90:
Alert ("left-handed -90,screen-width:" + Screen.width + "; Screen-height: "+ screen.height);
Break
Case 90:
Alert ("Right-handed 90,screen-width:" + Screen.width + "; Screen-height: "+ screen.height);
Break
Case 180:
Alert ("Landscape mode 180,screen-width:" + Screen.width + "; Screen-height: "+ screen.height);
Break
};<br>};
Add Event Listener
AddEventListener (' Load ', function () {
Orientationchange ();
Window.onorientationchange = Orientationchange;
});
5. Hide the Address bar & when handling events, prevent the scroll bar from appearing:
Hide the Address bar & prevent scroll bars from appearing when handling events
AddEventListener (' Load ', function () {
SetTimeout (function () {window.scrollto (0, 1);}, 100);
});
6. Two-hand finger swipe event:
Two-hand finger swipe event
AddEventListener (' Load ', function () {window.onmousewheel = Twofingerscroll;},
False//compatible with each browser, indicating that the event handler is called during the bubbling phase (true capture phase)
);
function Twofingerscroll (EV) {
var delta =ev.wheeldelta/120; Determine the delta value (for example, plus or minus) and then perform the appropriate action
return true;
};
7. Determine if it is an iphone:
Determine if the IPhone:
function Isapplemobile () {
Return (navigator.platform.indexOf (' IPad ')! =-1);
};
8. Localstorage:
Example: (Note data name N to enclose in quotation marks)
var v = localstorage.getitem (' n ')? Localstorage.getitem (' n '): ""; If the data with the name n is present, it is read out and given the variable v.
Localstorage.setitem (' n ', v); Writes data with a name of N and a value of V
Localstorage.removeitem (' n '); Delete data with name N
9. Use special Links:
If you turn off auto-recognition and want some phone numbers to link to your iPhone's dialing capabilities, you can use this to declare a phone link,
<a href= "tel:12345654321" > Call me </a>
<a href= "sms:12345654321" > Texting </a>
Or for cells:
<TD onclick= "location.href= ' tel:122 '" >
10. Automatic capitalization and auto-correction
To turn these two features off, you can use the Autocapitalize and AutoCorrect options:
<input type= "text" autocapitalize= "Off" autocorrect= "off"/>
One. WebKit CSS:
① "box Model" specifically describes the nature of the bounding box block content, including boundaries, padding, and so on.
-webkit-border-bottom-left-radius:radius;
-webkit-border-top-left-radius:horizontal_radius Vertical_radius;
-webkit-border-radius:radius; Container fillet
-webkit-box-sizing:sizing_model; Border constant Value: Border-box/content-box
-webkit-box-shadow:hoff voff blur color; Container Shadows (Parameters are: horizontal x-direction offset; vertical y-direction offset; Gaussian blur radius value; shadow color value)
-webkit-margin-bottom-collapse:collapse_behavior; Constant value: collapse/discard/separate
-webkit-margin-start:width;
-webkit-padding-start:width;
-webkit-border-image:url (borderimg.gif) Round/stretch Round/stretch;
-webkit-appearance:push-button; Built-in CSS performance, temporarily only support push-button
The ② "visual formatting Model" describes the nature of the block elements that determine the location and size.
Direction:rtl
Unicode-bidi:bidi-override; Constant: Bidi-override/embed/normal
③ "Visual Effects" describes properties that adjust the visual effects of block content, including overflow behavior, adjustment behavior, visibility, animation, transformations, and transitions.
Clip:rect (10px, 5px, 10px, 5px)
Resize:auto; Constant: auto/both/horizontal/none/vertical
visibility:visible; Constant: collapse/hidden/visible
-webkit-transition:opacity 1s linear; Animation effect Ease/linear/ease-in/ease-out/ease-in-out
-webkit-backface-visibility:visibler; Constants: Visible (Default)/hidden
-webkit-box-reflect:right 1px; Mirror reversal
-webkit-box-reflect:below 4px-webkit-gradient (linear, left top, left bottom,
From (Transparent), color-stop (0.5, transparent), to (white));
-webkit-mask-image:-webkit-gradient (linear, left top, left bottom, from (Rgba (0,0,0,1)), to (Rgba (0,0,0,0))); CSS Matte/Mask effects
-webkit-mask-attachment:fixed; Constant: Fixed/scroll
-webkit-perspective:value; Constant: None (default)
-webkit-perspective-origin:left top;
-webkit-transform:rotate (5DEG);
-webkit-transform-style:preserve-3d; Constant: flat/preserve-3d; (2D and 3D)
④ "generated content, AutoNumber, and List" describes the properties that allow you to change the content of a component, create an auto-numbered chapter and title, and manipulate the content of the style list.
Manuscripts: Diligent Learning qkxue.net
Extended reading:
WEBAPP Development Summary: HTTP://QKXUE.NET/INFO/25302/WEBAPP
WEBAPP Development Summary