The requirement is that the navigation of many pc web pages is fixed, such as google's homepage. Now we need to move this fixed navigation to mobile web, and naturally we will think of position: fixed; bottom: 0. It works normally in android, but problems may occur in iphone safari. When the scroll bar is rolling, the navigation bar will appear at the top of the screen, black and uncoordinated. Many people recommend iscroll, jquery mobile, and other frameworks, but sometimes it may take a long time to read the framework source code for secondary development. After a period of research, we found a solution, which is relatively simple, but still not as effective as pc web.
Copy codeThe Code is as follows: <div id = "fixnav" style = "position: absolute; z-index: 1000; height: 50px; opacity: 0.9;"> nav </div>
<Script type = "text/javascript">
$ (Window). scroll (function (){
// The key is the implementation of the following statement.
$ ("# Fixnav" ).css ({top: window. innerHeight + window. scrollY-$ ("# fixnav"). outerHeight ()});
});
</Script>
However, the latest ios5 supports position: fixed, which brings the gospel to the majority of web Front-end developers.
Author: qingliuyu