簡體   English   中英

編輯此表達式以將固定底部變為固定頂部

[英]Edit this expression to turn fixed bottom in fixed top

此功能可以在iPhone中使用,

$(document).ready(function() {
    $('#head').css('position','fixed');
  window.onscroll = function() {
      document.getElementById('head').style.top =
         (window.pageYOffset + window.innerHeight + 25) + 'px';
        // alert((window.pageYOffset + window.innerHeight - 25) + 'px');
    };
});

但是可以將div(25px)保持在頁面底部,無論滾動多少,我都需要在頁面頂部

我像這樣

$(document).ready(function() {
    $('#head').css('position','fixed');
    var height = $('#head').height();
  window.onscroll = function() {
      document.getElementById('head').style.top =
         (window.pageYOffset) - height + 'px';
        // alert(window.pageYOffset); alert(window.innerHeight);
    };
});

但似乎#head div沒有正確跟隨滾動(似乎彈跳),任何想法我都錯過了嗎?

fixed位置在iPhone中不起作用。 因此,每當您滾動頁面直到scroll處理程序設置其新位置時,它肯定會反彈。

$(document).ready(function() {
    $('#head').css('position','absolute');
    $(window).scroll(function() {
      $('#head').css({
         top: window.pageYOffset
      });
    });
});

再嘗試一下jQuery:

window.onscroll = function() { $('#head').offset(0,0); }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM