在滚动上更改标题的不透明度? [英] On scroll change opacity of header?

查看:95
本文介绍了在滚动上更改标题的不透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JQuery还是那么陌生,并且肯定答案是超基本的.但是,如果有人可以向我指出正确的方向,那就太好了.我只希望当用户滚动超过400像素时,标题的不透明度从0变为1.帮助? www.HULU.com有一个很好的例子.

Im so new to JQuery and im sure the answer is super basic. But if someone can point me in the right direction that would be great. I just want the opacity of my header to change from 0 to 1 as the user scrolls past 400 pixels. HELP? www.HULU.com has a perfect example.

<code>
<script>
$(document).ready(function() {
        $(window).scroll(function() {
            if ($(this).scrollTop() > 400) {
                $('.header').css("background", "#000");
            } else {
                $('.header').css("background", "transparent");
            }
        });
        });
</script>
</code>

推荐答案

尝试以下方法:

示例: http://jsfiddle.net/SEH5M/

HTML:

<div class="header">
    <div id="background"></div>
    <div id="labels">
        labels here
    </div>
</div>

<div class="content">
</div>

CSS:

.header{
    width:100%;
    height:100px;
    position:fixed;
    top:0px;
    z-index:3;
}

body{
    margin:0px;
}
.header #background, .header #labels
{
    position:absolute;
    top:0px;
    width:100%;
    height:100%;
}

.header #labels{
    background-color:transperent;
}

.header #background{
    background-color:yellow;
    display:none;
}


.content{
    width:100%;
    height:5000px;
    background-color:green;
}

jQuery:

$(window).scroll(function() {
    if ($(this).scrollTop() > 400) {
        $( ".header #background" ).fadeIn();
    } else {
        console.log('there');
        $( ".header #background" ).fadeOut();
    }
});

这篇关于在滚动上更改标题的不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆