如何使用标题在标题幻灯片中制作内容

时间:2013-12-11 01:54:08

标签: jquery html css scroll nav

理想情况下,我希望标题中的内容向上滚动以仅显示导航列表并在用户滚动时隐藏徽标(因此当用户使用时标题不占用屏幕上的空间)查看网站)。知道我做错了什么吗?截至目前,标题背景向上滑动,但标题内的内容保持不变。我假设有一个简单的解决方案,我很想念,谢谢。

HTML

<div id="header">
   <div id="address">
        <ul>
            <li>Address</li>
            <li>info@email.com</li>
            <li>(999) 999 9999</li>
        </ul>
    </div>

    <p id="logo">
        <img src="img/logo.png" />
    </p>

    <nav>
        <ul>
            <li><a href="#slider">Home</a></li>
            <li><a href="#wwd">What</a></li>
            <li><a href="#hwdi">How</a></li>
            <li><a href="#aboutanchor">Who</a></li>
            <li><a href="#workanchor">Work</a></li>
            <li><a href="#contact">Contact</a></li>
        </ul>
    </nav>
    <div style="clear:both;"></div>
</div>

CSS

body {
height: 5000px;
}
#header {
    height: auto;
    background-color: #f2f2f2;
    width: 100%;
    margin: 0;
    padding: 0;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
}

#address {
    width: 100%;
    background: #95c73a;
    height: 25px;
    padding-top: 5px;
}
    #address ul {
        float: left;
        margin: 0;
        padding: 0;
        position: relative;
        left: 50%;
        list-style: none;
    }

    #address li {
        float: left;
        color: #fff;
        margin: 0 15px;
        font-size: .5em;
        line-height: 18px;
        position: relative;
        right: 50%;
    }

    #address i {
        font-size: 1.25em;
        padding-right: 5px;
    }

    #address li:last-child i {
        font-size: 1.5em;
    }

    #logo {
        text-align: center;
        margin: 0;
    }

    nav {
        position: relative;
        margin-left: 50%;
        left: -345px;
        width: 690px;
        bottom: 0;
    }

    nav ul {
        margin: 0;
        padding: 0;
    }

    nav ul li {
        float: left;
        list-style: none;
        text-align: center;
    }

    nav ul li a i {
        padding-bottom: 5px;
        font-size: 1.4em;
        color: #333 !important;
        position: relative;
        top: 2px;
        margin-right: 5px;
    }

    nav ul li a {
        color: #333;
        display: block;
        padding: 20px;
        text-transform: uppercase;
        font-weight: 800;
        transition: color .2s ease-in-out;
    }

    nav ul li a:hover {
        color: #95c73a;
    }

JQuery的

$(function(){
        $('#header').data('size','big');
    });

    $(window).scroll(function(){
        var $nav = $('#header');
        if ($('body').scrollTop() > 0) {
            if ($nav.data('size') == 'big') {
                $nav.data('size','small').stop().animate({
                    height:'80px'
                }, 600);
            }
        } else {
            if ($nav.data('size') == 'small') {
                $nav.data('size','big').stop().animate({
                    height:'165px'
                }, 600);
            }  
        }
    });

JSFiddle - http://jsfiddle.net/bnsUB/143/

1 个答案:

答案 0 :(得分:0)

       $(window).scroll(function(){
            var $nav = $('#header');
            if ($('body').scrollTop() > 0) {
                if ($nav.data('size') == 'big') {
                    $('#logo').fadeOut(300);
                    $nav.data('size','small').stop().animate({
                        height:'80px'
                    }, 600);
                }
            } else {
                if ($nav.data('size') == 'small') {
                    $('#logo').fadeIn(300);
                    $nav.data('size','big').stop().animate({
                        height:'165px'
                    }, 600);
                }  
            }
        });

http://jsfiddle.net/bnsUB/146/