简体   繁体   English

当我向上滚动并在向上滚动或当我将鼠标悬停在上面时,如何使导航条变得透明?

[英]How do i make my nav bar transparent when I scroll down and come back when I scroll up or when I hover my mouse over is?

How do i make my nav bar transparent when I scroll down and come back when I scroll up or when I hover my mouse over it? 当我向上滚动并在向上滚动或当我将鼠标悬停在它上面时,如何使导航条变得透明? I tride to do this with jquery but i didn't really work. 我试图用jquery做这个,但我没有真正工作。 Here's My HTML and CSS: 这是我的HTML和CSS:

<DOCTYPE html>
<head>
    <link rel="stylesheet" type="text/css" href="LunchWebsiteCSS.css">
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">

    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
            $(window).scroll(
                {
                    previousTop: 0
                }, 
                function () {
                var currentTop = $(window).scrollTop();
                if (currentTop < this.previousTop) {
                    //$(".sidebar em").text("Up"); /* optional for demo */
                    $(".nav").css({ opacity: 0.5 });
                } else {
                    //$(".sidebar em").text("Down");
                    $(".nav").css({ opacity: 0 });
                }
                this.previousTop = currentTop;
            });

        });
    </script>
    <script src="js/jjquery.js"></script>
</head>
<body>
    <div class="nav">
        <ul>
            <div class="btn-group">
                <li><a href="#">Browse</a>

                </li>
                <li><a href="#">Sign Up</a>

                </li>
                <li>BHS Lunch</li>
                <li><a href="#">Log In</a>

                </li>
                <li><a href="#">Help</a>

                </li>
            </div>
        </ul>
    </div>

</body>

.nav {
height: 35px;
font-size: 16px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
width: 100%;
/*border: 1px solid black;*/
/*background-color: #AA3C39;*/
background-color: #AA3C39;
/*opacity: 0.7;*/
position: fixed;

} }

This is how you can do it. 这就是你如何做到的。

$(document).ready(function(){

    $(window).scroll(function(){

    if($(window).scrollTop()>100)
    $(".nav").css({"background-color" : "rgba(0,0,0,.5)"});

    else
    $(".nav").css({"background-color" : "rgba(0,0,0,1)"});


    });

});

Use CSS to see it back on hover 使用CSS在悬停时看到它

.nav:hover
{
 background-color:rgba(0,0,0,1);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么向下滚动时不重新加载数据,而在无限滚动中返回页面顶部时为什么不重新加载数据? - Why do not I reload the data when I scroll down and do it when I go back to the top of the page in my infinite scroll? 我试图让我的导航栏在我向下滚动时向上缩回,然后在我向上滚动时再次出现,但它没有做任何事情 - I'm trying to make my navbar retract upwards when I scroll down and then appear again when I scroll up, but it doesn't do anything 向下滚动时如何移动图像? - How do I make an image move when i scroll down? 向下滚动页面时,如何使导航栏下方出现阴影? - How do I make a shadow appear under the navigation bar when I scroll down the page? 在html和css中向下滚动时,如何使图像位于菜单栏后面? - How do I make the image go behind the menu bar when I scroll down in html & css? 如何获得锚链接,使其在向下滚动时像在其上一样平滑地向上滚动? - How can I get my anchor link to scroll smoothly back up top like it does when it goes down? 当页面滚动到达页脚时,如何使粘性侧边栏向上滚动? - How can I make my sticky sidebar to scroll up when page scroll reaches the footer? 当我滚动时,我的导航栏颜色不想随 jquery 改变? - My nav bar color doesn't want to change with my jquery when I scroll? 我希望我的导航栏在我向下滚动时消失并在我向上滚动时出现。 导航栏是固定的。 怎么了? - I want my navbar to disappear when I scroll down and appear when I scroll up. The navbar is fixed. What is wrong? 当我向下滚动时,元素将追加到父元素。 但是,当向上滚动时,如何恢复原始状态? - When i scroll down, element appends to parent element. But, when scroll up, how can I turn back original status?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM