javascript - Show a floating navigation bar on scroll - Stack Overflow

I am using blogspot, and I wanted to exactly achieve this kind of floating navigation bar:As you can s

I am using blogspot, and I wanted to exactly achieve this kind of floating navigation bar:

/

As you can see, when you scroll, the floating navigation bar shows as it slides down.

All I know is make a navigation bar:

<div id="floating-nav-content">
   <div class="floating-nav">
      <ul id="menu-floating-menu" class="menu">
         <li>...</li>
         <li>...</li>
         <li>...</li>
         <li>...</li>
      </ul>
   </div>
</div>

But the rest of the jQuery or javascript stuff is still unknown to me. I have also search but they don't teach exactly what I want.

I'm only new to jQuery and I still have no idea how to implement this.

Your help is much appreciated.

I am using blogspot, and I wanted to exactly achieve this kind of floating navigation bar:

http://apairandasparediy./

As you can see, when you scroll, the floating navigation bar shows as it slides down.

All I know is make a navigation bar:

<div id="floating-nav-content">
   <div class="floating-nav">
      <ul id="menu-floating-menu" class="menu">
         <li>...</li>
         <li>...</li>
         <li>...</li>
         <li>...</li>
      </ul>
   </div>
</div>

But the rest of the jQuery or javascript stuff is still unknown to me. I have also search but they don't teach exactly what I want.

I'm only new to jQuery and I still have no idea how to implement this.

Your help is much appreciated.

Share Improve this question asked May 1, 2015 at 7:42 kaynewilderkaynewilder 8537 gold badges28 silver badges53 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

This should do what you want. (assuming you've already included the jQuery library)

    <script type="text/javascript">
        $(document).scroll(function() {
            if ($(this).scrollTop() == 0) {
                $("#floating-nav-content").slideUp(400);
            } else {
                $("#floating-nav-content").slideDown(600);
            }

        });
    </script>

The CSS is also important, because this places the navigation bar in a fixed position on top of your page.

    <style type="text/css">
        html, body {
            margin: 0;
            padding: 0;
        }

        #floating-nav-content {
            top: 0;
            width: 100%;
            height: 20px;
            background-color: #000;
            position: fixed;
            display: none;
            color: #FFF;
            padding: 5px;
        }
    </style>

And ofcourse the HTML. I placed all of the above and below in the body tag.

    <div id="floating-nav-content">
        Content
    </div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745432228a4627443.html

相关推荐

  • javascript - Show a floating navigation bar on scroll - Stack Overflow

    I am using blogspot, and I wanted to exactly achieve this kind of floating navigation bar:As you can s

    5小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信