jquery navigation color and height change on scroll

被刻印的时光 ゝ 提交于 2019-12-06 03:40:18

Hi you can check this to begin : http://jsfiddle.net/rcAev/177/

Here i made this function:

$(document).ready (function () {
 $(window).scroll (function () {
    var sT = $(this).scrollTop();
        if (sT >= 300) {
            $('.overlay').addClass('cambio')
        }else {
            $('.overlay').removeClass('cambio')
        }
  })
})

I'll explain you step by step:

  • First this executes the function every time you scroll the window

$(window).scroll (function ()

  • Second read the value from the top of the scroll to know how much you advance

var sT = $(this).scrollTop();

  • Third compare to the breakpoint you want , in this case i choose 300 because i want to change the nav after pass the height form the image.

    if (sT >= 300) {
            /*action you want after the 300 or more scroll*/
        }else {
            /*action you want before the 300 scroll*/
        }
    
  • Fourth to change the transparent to color the action i apply is add a class with new background and different height:

    $('.overlay').addClass('cambio')
    

In this site, the navigation height is not actually changing. It's fixed positioning. The navigation is positioned relative to the browser window.

jsfiddle

HTML:

<ul class="nav nav-pills">
  <li class="active"><a href="#">Home</a></li>
  <li><a href="#">Profile</a></li>
  <li><a href="#">Messages</a></li>
</ul>
<div id="first"></div><div id="second"></div><div id="third"></div>

CSS:

ul.nav{
    position:fixed;
}
div#first{
    height:600px;
    width:100%;
    background:#59071D;
}
div#second{
    height:600px;
    width:100%;
    background:#735448;
}
div#third{
    height:600px;
    width:100%;
    background:#F2DDB6;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!