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
In today’s front-end pages, especially on mobile devices, it is often necessary to suspend the
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.
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
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.
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
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