最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CSS Dropdown Menu Appear Animation - Stack Overflow

programmeradmin0浏览0评论

I am using a list for the nav for the nav of my website and when a user hovers over certain list items a dropdown appears with extra navigation options. In my case when a user hovers over the "Brands" item then a dropwdown appears with all the different brands. At the moment the dropdown appears instantly however I'd like it to appear in a motion as if it is sliding down rather than just appearing instantly. Is this possible with CSS or do I need some jQuery magic ?? Code:

HTML:

    <section id="nav">

        <div id="nav-wrapper">

            <ul id="nav-list">

                <li id="nav-home"><a href="">Home</a>
                </li>
                <li id="nav-brands"><a href="">Brands</a>
                    <ul id="brands-list">
                        <li><a href="">Brand 01</a>
                        </li>
                        <li><a href="">Brand 02</a>
                        </li>
                        <li><a href="">Brand 03</a>
                        </li>
                        <li><a href="">Brand 04</a>
                        </li>
                        <li><a href="">Brand 05</a>
                        </li>
                    </ul>
                </li>
                <li id="nav-about"><a href="">About Us</a>
                </li>
                <li id="nav-contact"><a href="">Contact Us</a>
                </li>

            </ul>

        </div>

    </section>

CSS :

#nav-brands { position:relative; }

#nav-list li:hover ul { display: block; opacity: 1; visibility: visible; background-color: #fff; }

#brands-list { padding: 10px 0px 0px 0px; position: absolute; top: 20px; left: -35px; width: 120px; box-shadow: none; display: none; opacity: 0;
               visibility: hidden; -webkit-transiton: opacity 0.2s; -moz-transition: opacity 0.2s; -ms-transition: opacity 0.2s;
               -o-transition: opacity 0.2s; -transition: opacity 0.2s; border:thin solid #000000; border-radius:0px 0px 5px 5px;
               border-top:0px;
}

#brands-list li { display: block; margin:0px 0px 5px 0px; padding:0px 0px 5px 0px; text-align:center; border-bottom:thin solid #CECECE;

}

#brands-list li:hover {}

#brands-list li:last-child { border-bottom:0px; }

I am using a list for the nav for the nav of my website and when a user hovers over certain list items a dropdown appears with extra navigation options. In my case when a user hovers over the "Brands" item then a dropwdown appears with all the different brands. At the moment the dropdown appears instantly however I'd like it to appear in a motion as if it is sliding down rather than just appearing instantly. Is this possible with CSS or do I need some jQuery magic ?? Code:

HTML:

    <section id="nav">

        <div id="nav-wrapper">

            <ul id="nav-list">

                <li id="nav-home"><a href="">Home</a>
                </li>
                <li id="nav-brands"><a href="">Brands</a>
                    <ul id="brands-list">
                        <li><a href="">Brand 01</a>
                        </li>
                        <li><a href="">Brand 02</a>
                        </li>
                        <li><a href="">Brand 03</a>
                        </li>
                        <li><a href="">Brand 04</a>
                        </li>
                        <li><a href="">Brand 05</a>
                        </li>
                    </ul>
                </li>
                <li id="nav-about"><a href="">About Us</a>
                </li>
                <li id="nav-contact"><a href="">Contact Us</a>
                </li>

            </ul>

        </div>

    </section>

CSS :

#nav-brands { position:relative; }

#nav-list li:hover ul { display: block; opacity: 1; visibility: visible; background-color: #fff; }

#brands-list { padding: 10px 0px 0px 0px; position: absolute; top: 20px; left: -35px; width: 120px; box-shadow: none; display: none; opacity: 0;
               visibility: hidden; -webkit-transiton: opacity 0.2s; -moz-transition: opacity 0.2s; -ms-transition: opacity 0.2s;
               -o-transition: opacity 0.2s; -transition: opacity 0.2s; border:thin solid #000000; border-radius:0px 0px 5px 5px;
               border-top:0px;
}

#brands-list li { display: block; margin:0px 0px 5px 0px; padding:0px 0px 5px 0px; text-align:center; border-bottom:thin solid #CECECE;

}

#brands-list li:hover {}

#brands-list li:last-child { border-bottom:0px; }
Share Improve this question asked Jul 24, 2014 at 12:28 MikeyMikey 3961 gold badge4 silver badges20 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

No Jquery magic.

A css approach would be to wrap your sublist within a div. Use that div to set the submenu position, and then use an overflow / transition trick to give to the inner list the sliding effect you are looking for.

See it here: http://jsfiddle/vrGfc/

Also, remove the hover effect from the submenu itself. It will only need to be applied to the wrapper div.

See an example

http://jsfiddle/DHW9v/1/

You need set transition-timing-function

transition: opacity .8s ease-in-out;

There's no need for any jQuery or anything like that here - the css properties you're looking for are "transitions" - http://www.w3schools./css/css3_transitions.asp

发布评论

评论列表(0)

  1. 暂无评论