编辑此表达式将固定底部变为固定顶部

Edit this expression to turn fixed bottom in fixed top

本文关键字:顶部 底部 编辑 表达式      更新时间:2023-09-26

这个函数应该在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)应该在页面底部,我需要它在页面顶部不管我滚动多少

i'm string like this

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

但似乎#headdiv没有正确地跟随滚动(似乎它反弹),任何想法我错过了什么??

位置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); }