Home Web Front-end H5 Tutorial 3 ways to solve the problem that the floating layer (floating header, footer) blocks the content on the mobile terminal_html5 tutorial skills

3 ways to solve the problem that the floating layer (floating header, footer) blocks the content on the mobile terminal_html5 tutorial skills

May 16, 2016 pm 03:46 PM
Mobile terminal

In today’s front-end pages, especially on mobile devices, it is often necessary to suspend the

or
modules and keep them positioned at the top or bottom of the page following the sliding of the page, as follows As shown in the figure.

The "Reply Topic" module follows the floating of the page and is always suspended at the bottom of the page. The code structure is as follows.


Copy code
The code is as follows:

...

...

To achieve such a function, of course, you need to use position:fixed. However, there is a bug in using position: fixed. Take the floating

at the bottom as an example (the same goes for floating
). When the page slides to the bottom, it is out of the normal document flow due to fixed positioning. , resulting in some content being obscured. As shown below:

The left side above is the problematic display, and the right side is the normal display. So, how to solve this problem? Here, I would like to put forward three of my opinions, hoping to find a better way.

Method 1. Javasrript solution

Use js to solve the problem. When the slider slides to the bottom of the page content, change the fixed positioning that will originally break away from the document flow to the relative positioning that does not break away from the document flow.

Using scripts to solve problems is the most arduous method. Try not to use scripts if they can be solved with css, but it is still a method.

Copy code
The code is as follows:

//Scroll bar on the Y axis Scroll distance
function getScrollTop(){
return document.body.scrollTop;
}
//The total height of the document
function getScrollHeight(){

Return document.body.clientHeight;
}
//Height of browser viewport
function getWindowHeight(){
var windowHeight = 0;
if(document.compatMode == "CSS1Compat")
 {
 windowHeight = document.documentElement.clientHeight;
 }
else
{
🎜 > Return windowHeight;
}

//Sliding monitoring
window.onscroll = function(){
//When sliding to the bottom, the footer is set to the bottom, assuming that the height of

is 60
if((getScrollHeight () - getScrollTop() - getWindowHeight()) > 61)
$('.footer').css('position','fixed');
else
$('.footer' ).css('position','relative');
}


Method 2. Add padding-bottom to the body

Add a padding-bottom attribute to the html tag, so that the content of the normal document flow will be a distance set by padding-bottom from the bottom of the body.

The disadvantage is that considering the reuse of modules and the frequent need to merge css files after the project is launched, when other pages do not need this floating block, it will burden pages that do not require

How to use mobile gesture operations in Vue projects How to use mobile gesture operations in Vue projects Oct 08, 2023 pm 07:33 PM

How to use mobile gesture operations in Vue projects With the popularity of mobile devices, more and more applications need to provide a more friendly interactive experience on the mobile terminal. Gesture operation is one of the common interaction methods on mobile devices, which allows users to complete various operations by touching the screen, such as sliding, zooming, etc. In the Vue project, we can implement mobile gesture operations through third-party libraries. The following will introduce how to use gesture operations in the Vue project and provide specific code examples. First, we need to introduce a special

Solve the problem of multi-touch points on Vue mobile terminal Solve the problem of multi-touch points on Vue mobile terminal Jun 30, 2023 pm 01:06 PM

In mobile development, we often encounter the problem of multi-finger touch. When users use multiple fingers to swipe or zoom the screen on a mobile device, how to accurately recognize and respond to these gestures is an important development challenge. In Vue development, we can take some measures to solve the problem of multi-finger touch on the mobile terminal. 1. Use the vue-touch plug-in vue-touch is a gesture plug-in for Vue, which can easily handle multi-finger touch events on the mobile side. We can install vue-to via npm

How to solve the double-click amplification problem on mobile terminals in Vue development How to solve the double-click amplification problem on mobile terminals in Vue development Jun 29, 2023 am 11:06 AM

With the popularity of mobile devices, using Vue for mobile development has become a common choice. However, we often face a problem during mobile development, which is double-clicking to zoom in. This article will focus on this problem and discuss how to solve the specific method of double-click amplification on the mobile terminal in Vue development. The double-click enlargement problem on mobile devices occurs mainly because the mobile device automatically enlarges the zoom ratio of the web page when double-clicking on the touch screen. For general web development, this kind of double-click to enlarge is usually beneficial because it can

A complete guide to implementing mobile responsive layout in Vue (Vant) A complete guide to implementing mobile responsive layout in Vue (Vant) Jun 09, 2023 pm 04:09 PM

A Complete Guide to Implementing Mobile Responsive Layout in Vue (Vant) Mobile responsive layout is a very important part of modern web development. With the popularity of mobile devices, how to quickly respond to the size and resolution of the user's mobile phone screen has become a One of the challenges front-end engineers have to face. The Vue framework comes with responsive layout features, and there are also many third-party libraries to help us implement responsive layout. Among them, Vant component library is a Vue mobile UI library because it is very powerful, easy to use and customized, and is fully compatible with mobile devices.

How to implement mobile map positioning function using Python and Baidu Map API How to implement mobile map positioning function using Python and Baidu Map API Jul 29, 2023 pm 11:33 PM

Method of implementing mobile map positioning function using Python and Baidu Map API. With the development of mobile Internet, map positioning function has become more and more common in mobile applications. Python, as a popular programming language, can also implement mobile map positioning functions by using Baidu Map API. The following will introduce the steps to implement the map positioning function using Python and Baidu Map API, and provide corresponding code examples. Step 1: Apply for Baidu Map API Key Before starting, we first need to apply

Vue development: Optimizing the stuck problem of gesture scaling on the mobile terminal Vue development: Optimizing the stuck problem of gesture scaling on the mobile terminal Jun 30, 2023 pm 04:33 PM

How to solve the stuck problem of mobile gesture zooming pages in Vue development. In recent years, the popularity of mobile applications has made gesture operations an important way of user interaction. In Vue development, implementing the gesture zoom function on the mobile terminal often encounters the problem of page lag. This article will explore how to solve this problem and provide some optimization strategies. Understand the principle of gesture scaling. Before solving the problem, we first need to understand the principle of gesture scaling. Gesture zooming is implemented by listening to touch events. When the user slides the screen with two fingers, the page will follow the sliding movement of the fingers.

How to handle mobile and responsive design in PHP forms How to handle mobile and responsive design in PHP forms Aug 10, 2023 am 11:51 AM

How to deal with mobile and responsive design in PHP forms. With the popularity and frequency of mobile devices increasing, and more and more users using mobile devices to access websites, adapting to mobile has become an important issue. When dealing with PHP forms, we need to consider how to achieve a mobile-friendly interface and responsive design. This article explains how to handle mobile and responsive design in PHP forms and provides code examples. 1. Responsive forms using HTML5 HTML5 provides some new features that can easily implement responsive forms.

How to solve the mobile terminal sliding conflict problem in Vue development How to solve the mobile terminal sliding conflict problem in Vue development Jun 29, 2023 pm 12:24 PM

How to solve the problem of mobile sliding conflicts in Vue development. The popularity of mobile applications has made mobile development more and more important. When developing mobile applications, sliding conflicts are often encountered. In Vue development, we can use some techniques to solve this problem and ensure the user's sliding experience. Using a Single Swipe Direction On mobile, users tend to browse content by swiping up and down or left and right. If there are multiple scroll areas in our application and the user is allowed to swipe in different areas at the same time, a sliding conflict will occur.

See all articles