モバイルブラウザ(iosおよびAndroid)で要素の位置を固定する方法iOS <5およびAndroid <4では、要素は引き続き以下のコードでスクロールします
<html>
<head>
<style>
.fixed{
position:fixed;
top:0;
left:0;
}
</style>
</head>
<body>
<div class="fixed">
Hi I m Position Fixed
</div>
<div>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
sample text<br/>
</div>
</body>
</html>
position: fixed
は、iOS
およびBlackberry
のほとんどの古いバージョンでは機能しません。ほとんどのモバイルブラウザでこの修正を試みましたが、JavaScript
プラグインなしでスムーズに機能しました。
.fixed {
position: fixed;
top: 0px;
left: 0px;
width: 320px;
height: 50px;
background: red;
-webkit-backface-visibility: hidden;
/*--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Most Important*/
}
<div class="fixed">
Hi I m Position Fixed
</div>
<div>
sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>sample text
<br/>
</div>