Position:fixed and Overflow:auto do a simple layout to achieve the effects we need, while on the phone side we encounter the following problems:
- position:fixed is not supported under iOS4 and android2.2
- iOS does not support Overflow:auto
- iOS4 and android2.3 below and not supported Overflow-scrolling
The most serious result is that scrolling area content cannot be dragged
There are 2 layout methods that can be overridden for issues that do not support position:fixed iOS4 and android2.2. Layout One: Define the overall height of the page as 100%, then use the Position:absolute layout to resolve
/*<!--absolute layout [[--><body> <div class= "header" >header</div> <div class= "main" > Elastic scrolling Area </div> <div class= "footer" >footer</div></body><!--Absolute Layout]) --*/Html,body{Height:100%;}. Header,.footer{Height:40px;Line-height:40px;Background-color:#D8D8D8;text-align:Center;}. Header{position:Absolute;Top:0; Left:0;width:100%;}. Footer{position:Absolute;Bottom:0; Left:0;width:100%;}. Main{position:Absolute;Z-index:1;Top:40px; Left:0;Bottom:40px;width:100%;}
Layout Two: define the overall height of the page as 100%, then use the Display:flex layout to solve
/*<!--flex layout [[--><body><div class= "wrap" > <div class= "header" >header</div> &L T;div class= "main" > Elastic scrolling Area </div> <div class= "Footer" >footer</div></div></bo dy><!--Flex Layout]) --*/Html,body{Height:100%;}. Wrap{Display:-webkit-box;Display:-webkit-flex;Display:-ms-flexbox;Display:Flex;-webkit-box-orient:Vertical;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;width:100%;Height:100%;}. Header,.footer{Height:40px;Line-height:40px;Background-color:#D8D8D8;text-align:Center;}. Main{-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;Flex:1;width:100%;}
then the main problem is that the child container height exceeds the height of the parent container and how the content of the child container scrolls. For how to use elastic scrolling, there is no best solution, the specific look at the product user groups, product positioning, etc., a brief introduction:
Scenario One: Overflow:auto and-webkit-overflow-scrolling:touch
Overflow:auto is useful in Winphone8 and android4+. The ios5+ version adds a new attribute: overflow-scrolling This property activates smooth scrolling and works well.
. CSS {overflow:auto; /* */-webkit-overflow-scrolling: Touch/**/}
Suitable scene: If the user group of the product is mostly ios5+, android4+ user, it is recommended to use overflow-scrolling to make the difference experience, after all Iscroll4.js under the Android machine experience is not smooth, in addition also loaded the JS code of more than 10K.
Scenario two: Iscroll4.js and Overflow:auto
Once wrote "Use Iscroll.js to solve the problem of iOS4 does not support position:fixed," using iscroll4.js basically solved the page elastic scrolling problem, summed up the Iscroll4.js experience:
- Very good performance on iOS system, smooth Scrolling
- Poor performance on some Android systems, especially when scrolling the area, the scrolling page will appear
- There are a lot of bugs in iOS and Android, such as the page height is not recalculated, splash screen, etc. (not discussed here) after the form has been scorched and the soft keyboard is popped
- Winphone not supported
So the solution here is that the page is initialized with the Weibit browser enabled Iscroll4.js
<class= "wap Ie-ova" ID= ""><!-- --... </ Div >
Winphone8 Mobile phone use the following hack
{ . ie-ova{overflow:auto/**/}
suitable for the scene: if the user base of the product has iOS and most android2+ users, and the page data in Android is relatively simple (usually elastic scrolling data only text), then the use of iscroll4.js can ensure that the android2+ machine display normal and not lag, Let iOS users scroll more smoothly.
Scenario Three : Iscroll4.js and Overflow:auto and Android2x.css .
if the product's user base has iOS and most android2+ users, and the page data in Android is more complex (usually with a large number of elastic scrolling data), then the android2+ machine can be statically positioned to display (position:static), The page does not have scrolling effect, and iscroll4.js is still used for iOS users.
<rel= "stylesheet" href= "Android2x.css"> <!-- -
. CSS {overflow:auto; /* */}
<class= "WAP" ID= ""><!-- - ... </ Div >