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

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 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

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

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

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.

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 use PHP to generate a QR code that can be used on mobile terminals? How to use PHP to generate a QR code that can be used on mobile terminals? Aug 26, 2023 pm 02:51 PM

How to use PHP to generate a QR code that can be used on mobile terminals? With the rapid development of mobile Internet, QR codes have become an important tool for merchant promotion, payment, activities and other aspects. Using PHP to generate QR codes that can be used on mobile terminals has become a need of many developers. In this article, we will introduce how to use PHP to generate QR codes that can be used on mobile terminals, and attach code examples for reference. First, we need to install and introduce a PHP library named "endroid/qr-code". This library provides a

How to solve the problem of mobile image rotation in Vue development How to solve the problem of mobile image rotation in Vue development Jun 29, 2023 pm 09:22 PM

With the rapid development of the mobile Internet, more and more websites and applications are beginning to use Vue.js for mobile development. However, during mobile development, we often encounter the problem of image rotation. Image rotation means that when a user takes a photo on a mobile device, due to the change in device orientation, the angle of the photo displayed on the page is inconsistent with the actual shooting angle. To solve the problem of image rotation, you first need to understand the reason why the image is rotated. When a user takes a photo on a mobile device, the device automatically adds some metadata to the photo.

See all articles