現在很多for Mobile的HTML5網頁內都有快速滾動和回彈的效果,看上去和原生app的效率都有得一拼。
要實現這個效果很簡單,只需要加一行css代碼即可:
-webkit-overflow-scrolling : touch;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset="utf-8" />
<title>scroll</title>
<style type="text/css">
.container {
width : 300px;
height : 50%;
-webkit-box-sizing : border-box;
position : relative;
overflow-y : auto;
background-color : cyan;
-webkit-overflow-scrolling : touch; /* liuhx:可以把這整行注釋掉對比差別 */
}
ul {
height: 50px;
}
</style>
</head>
<body>
<div align="center">
<nav class="container">
<ul>1</ul>
<ul>2</ul>
<ul>3</ul>
<ul>4</ul>
<ul>5</ul>
<ul>5</ul>
<ul>5</ul>
<ul>5</ul>
<ul>5</ul>
<ul>5</ul>
<ul>5</ul>
<ul>5</ul>
<ul>5</ul>
<ul>5</ul>
</nav>
</div>
</body>
</html>
可以用手指滑動中間的藍色區域,會發現回彈效果以及滾動得很快: