【jQuery代码】使用jQuery库检查网頁底部的位置并在必要時對頁面元素進行调整

需求:

jQuery判斷,footer版块齣現在可視範圍時,计算footer版块顶部到窗口底部的距離,并且把该距離+60px,赋予.freecatalog增加bottom屬性


解決方案:

$(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', '');
  }
}
}

這段代码使用了jQuery库來检查网頁底部的位置,以便在必要時對頁面元素進行调整。具體來說,當窗口滚動或頁面加載完成後,将调用名為"checkFooterPosition()"的函数來检查頁面底部的位置。如果浏覽器宽度大于1280像素,则會检查是否到達了頁面底部。如果已經到達頁面底部,则會将一個名為"freecatalog"的元素向上移動60個像素以避免與頁脚重叠。如果没有到達頁面底部,则不做任何调整。

標簽:jQuery
不喜歡2

本文链接:https://zh-tw.finchui.com/program/28.html

网友評論

猜你喜歡

熱門商品
熱門文章
熱門標簽
相關標簽
FinchUI商店版 香港特惠專區

分享

復制链接

星岚工作室添加好友

上班時间:9:00-22:00
周六、周日:14:00-22:00
wechat
扫码添加客服微信