Everyone opens Baidu and Taobao through the browser that comes with their mobile phone. After the homepage is loaded, the address bar at the top of the page will be automatically hidden. In addition, these websites are optimized for mobile browsers. At first glance, it is really difficult to distinguish them. Is this a WEB APP or a Native App? The picture on the left below shows the homepage of Taobao opened through Safari. If it weren’t for the browser toolbar underneath, it would really look like a Native App. In fact, it has an address. Drag it down and you will see the address bar, as shown in the picture on the right below.
How to hide the browser address bar? Baidu, there is a lot of information, it is very simple. It mainly uses the window.scrollTo() method to scroll the current page up on the screen, causing the address bar to exceed the field of view, as follows:
<script> <br>window.onload=function(){ <br>setTimeout(function() { <br>window.scrollTo(0, 1) <br>}, 0); <br>}; <br></script>
But if you make a simple page, for example, only In a word, with the above script, you will sadly find that
the address bar is not automatically hidden ; does the window.scrollTo() method not take effect in this browser?
But if your web page contains a lot of content and exceeds the height of the screen, the address bar will be automatically hidden;
How to hide the address bar when there is less content? Before scrolling, the program needs to dynamically set the height of the body. Add the following code:
if(document.documentElement.scrollHeight <= document.documentElement.clientHeight) {
bodyTag = document.getElementsByTagName('body')[0];
bodyTag.style.height = document.documentElement .clientWidth / screen.width * screen.height 'px';
}
The following is an example of a page (the address bar is hidden by default). The picture on the right is a screenshot of the address bar after pulling down. :
我是个网页,但不显示滚动条 <script> <br>window.onload=function(){ <br>if(document.documentElement.scrollHeight <= document.documentElement.clientHeight) { <br>bodyTag = document.getElementsByTagName('body')[0]; <br>bodyTag.style.height = document.documentElement.clientWidth / screen.width * screen.height 'px'; <br>} <br>setTimeout(function() { <br>window.scrollTo(0, 1) <br>}, 0); <br>}; <br></script>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31