最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Fixed Header Transformation When Page is Scrolled - Stack Overflow

programmeradmin4浏览0评论

I can't for the life of my figure this out. Does anyone know how this scrolling effect is created on this website? -

I'm working on a project where this effect would greatly help so that my fixed navigation isn't too large when scrolling.

Thanks in advance.

I can't for the life of my figure this out. Does anyone know how this scrolling effect is created on this website? - http://blindbarber./news

I'm working on a project where this effect would greatly help so that my fixed navigation isn't too large when scrolling.

Thanks in advance.

Share Improve this question asked Feb 19, 2012 at 19:25 GuerillaRadioGuerillaRadio 1,2975 gold badges30 silver badges60 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13

The header stays on top with the css position:fixed .. either you can set the header css -- position:fixed right from the start or change it to position:fixed once he starts scrolling the page.. and update the header to the contents you want to keep as he scrolls..

// css
.container {
  height: 2000px;
  width: 100%;
  background-color: yellow;
}

.header {
  text-align: center;
  background-color: red;
  height: 100px;
  min-height: 50px;
  width: 100%;
}

// js

window.onscroll= function () {
  var top = window.pageXOffset ? window.pageXOffset : document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
  var header = document.getElementById("header");
  if (top > 50){
    header.style.position = "fixed";
    header.style.height = "50px";
  } else {
    header.style.position = "relative";
    header.style.height = "100px";
  }
}

//html
<div class="container">
  <div id="header" class="header">
    Hello World
  </div>
</div>

Demo here

This is what your looking for I think:

http://www.backslash.gr/content/blog/webdevelopment/6-navigation-menu-that-stays-on-top-with-jquery

So the google search terms that gives you an answer is "responsive menu" + javascript.

In my case I was looking for a jquery plugin so I added in "jquery". I didn't find much using "fixed header transformation"

:)

发布评论

评论列表(0)

  1. 暂无评论