我有一個問題已經解決了一天左右,我正在創建一個在線商店,當您訪問特定商品的頁面時,您有一個固定的[添加到購物車]按鈕作為頁腳,當我滾動到特定點,它應該變為靜態,唯一的區別是我需要它作為頁眉,而不是頁腳。這是我的 jquery 代碼:const myFunction = () => {let lastScrollTop = 0$(window).scroll(() => {? const footerTop = $('.wrapper-footer')?.offset()?.top || null? const container = $('.wrapper-mobile-price')? const containerHeight = wrapperMobilePrice.height()? const bottomOfScreen = $(window).scrollTop() + $(window).innerHeight()? const st = $(window).scrollTop()? if (st > lastScrollTop) {? ? if (bottomOfScreen > footerTop + (containerHeight / 2)) {? ? ? container.css({position: 'static'})? ? }? } else {? ? if (bottomOfScreen + containerHeight < footerTop) {? ? ? container.css({position: 'fixed'})? ? }? }? lastScrollTop = st})}如果有解決辦法請幫忙,謝謝!
在頁腳滾動上保持固定
楊魅力
2023-07-06 19:51:52