【问题标题】:How to make content within header slide with header如何使用标题在标题幻灯片中制作内容
【发布时间】:2013-12-11 01:54:07
【问题描述】:

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

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/

【问题讨论】:

    标签: jquery html css scroll nav


    【解决方案1】:
           $(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/

    【讨论】:

    • @user3089222 请将此答案标记为已接受,它解决了您的问题。否则给予反馈,谢谢。
    • 解决了,谢谢。如何标记为已解决不是很直观,我的错误。
    猜你喜欢
    • 2022-08-21
    • 2019-01-18
    • 2019-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    相关资源
    最近更新 更多