“Reverse” sticky header

北城以北 提交于 2021-01-28 20:54:52

问题


I am trying to implement a header that is originally fixed and stays on top, then, as a certain element or scrolling position is reached, it will scroll out of the viewport as if it were "normal" content.

What I did until now is this code using the Jquery Waypoints plugin:

$('h1').waypoint(function(direction) {
    $(".header-container").slideToggle();
});

It basically animates the header out of sight as soon as a certain element (in this case h1) is reached. But I want it to be scrollable by the user.

I hope I made myself clear, it's kind of difficult to explain :)

Any ideas would be greatly appreciated.


回答1:


You could try to replace JQuery Wayppints with JQuery ScrollToFixed. Their Full demo is just gorgeous. I think it does exactly what you're looking for.

$('.header').scrollToFixed({
    preFixed: function() { $(this).find('h1').css('color', 'blue'); },
    postFixed: function() { $(this).find('h1').css('color', ''); }
});


来源:https://stackoverflow.com/questions/17989439/reverse-sticky-header

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!