-1

我从这个页面得到了一个想法。我尝试使用此脚本,但它不起作用。

$(window).load(function(){
$(function() {
  var a = function() {
    var b = $(window).scrollTop();
    var d = $("#menu-anchor").offset({scroll:false}).top;
    var f = $(".logo-anchor").offset({scroll:false}).top;
    var c = $("#menu");
    var e = $(".logo");
    if (b>d) {
      c.css({position:"fixed",top:"0px"})
    } else {
      if (b<=d)   {
        c.css({position:"relative",top:""})
      }
    };
    if (b>d) {
      e.css({position:"fixed",top:"0px"})
        }else {
          if (b<=f)   {
            e.css({position:"fixed",top:""})
          }
        }
      };
  $(window).scroll(a);a()
});
});

4

1 回答 1

0

Just try like that:

http://jsfiddle.net/3pGGv/

I don't change the position: fixed, but set the value for "top" every time the window is scrolled.

于 2012-09-26T06:52:45.340 回答