修复了带有css转换的标头

时间:2013-07-19 09:30:08

标签: jquery css3

我在转换时遇到以下问题:

CSS

header {
    display:block;
    width:100%;
    height:120px;
    background-color:#000;
    transition: all 1s ease 0s;
}

#content {
    height:800px;
    border:1px solid #000;
}

.headerSticky {
    position:fixed;
    top:0;
    z-index:1000;
    transition: all 1s ease 0s;
}

HTML

<header>lala</header>
<div id="content">
    <span class="test">test</span>
</div>

的Javascript

$('.test').waypoint(function(direction) {
  if(direction == 'down')
    $('header').addClass('headerSticky');
  else
    $('header').removeClass('headerSticky');
});

http://jsfiddle.net/SwLdb/

我有一个标题,我希望当滚动到达项目时(使用jquery waypoint),标题将被固定在顶部。但是我希望这一过渡过程看起来不错。

有可能吗?

感谢

1 个答案:

答案 0 :(得分:0)

执行此操作的一种好方法可能是将标题设置为需要的位置$(window).scrollTop();,然后将类更改为headerSticky。用户将无法注意到它,但您将获得所需的效果。

  if(direction == 'down')
  {
    $('header').animate({top:$(window).scrollTop()},500,function()
    {
        $('header').addClass('headerSticky',500);
    }
  }
  else
    $('header').removeClass('headerSticky',500);