Sign in QQ login WeChat login
All categories

[jQuery Code] Use the jQuery library to check the position of the bottom of the page and adjust the page elements if necessary

finchui six hundred and sixty-nine 2023-04-30 23:56:03

Requirements:

use jQuery Judge that when the footer section appears in the visual range, calculate the distance from the top of the footer section to the bottom of the window, and give the distance+60px to. freecatalog to add the bottom attribute


Solution:

 $(document).ready(function() {   checkFooterPosition(); }); $(window).scroll(function() {   checkFooterPosition(); }); function checkFooterPosition() {   var windowBottom = $(window).scrollTop() + $(window).height();   var footerTop = $('footer').offset().top;   var A = $(document).width();   if (A > 1280) {   if (windowBottom >= footerTop) {      var distance = windowBottom - footerTop + 60;      $('.freecatalog').css('bottom', distance);   } else {      $('.freecatalog').css('bottom', '');   } } }

This code uses the jQuery library to check the position of the bottom of the page, so as to adjust the page elements if necessary. Specifically, when the window scrolls or the page is loaded, a function named "checkFooterPosition()" will be called to check the position of the bottom of the page. If the browser width is greater than 1280 pixels, it will check whether it has reached the bottom of the page. If you have reached the bottom of the page, an element named "freecatalog" will be moved up 60 pixels to avoid overlapping with the footer. If it does not reach the bottom of the page, no adjustment will be made.

label: jQuery
  • Dislike( two

Link to this article: https://www.finchui.com/program/28.html

Guess you like it

Netizen comments

Hot commodity
Popular articles
Hot tags
Related labels
 FinchUI Store Edition

share

Copy Link

Xinglan Studio Online consultation

Working hours: 9:00-22:00
Saturday and Sunday: 14:00-22:00