• 一款活动下拉式菜单的制作 ( jQuery & CSS )


    一款活动下拉式菜单的制作 ( jQuery & CSS )

    Web Design 2010-08-17 16:38:04 阅读437 评论2   字号: 订阅

    之前介绍过几款导航的制作,反应比较好,今天再为大家介绍一款有子菜单的导航,也是利用 CSS & jQuery 功能制作的。

    一款活动下拉式菜单的制作 ( jQuery  CSS ) - Airos Chou - Sunflowa Media

    一款活动下拉式菜单的制作 ( jQuery  CSS ) - Airos Chou - Sunflowa Media

    Step1. 创建HTML

    <ul class="topnav">
        <li><a href="#">Home</a></li>
        <li>
        <a href="#">About Me</a>
        <ul class="subnav">
        <li><a href="#">Sub Nav Link</a></li>
        <li><a href="#">Sub Nav Link</a></li>
        </ul>
        </li>
        <li>
        <a href="#">Portfolio</a>
        <ul class="subnav">
        <li><a href="#">Sub Nav Link</a></li>
        <li><a href="#">Sub Nav Link</a></li>
        <li><a href="#">Sub Nav Link</a></li>
        <li><a href="#">Sub Nav Link</a></li>
        <li><a href="#">Sub Nav Link</a></li>
        </ul>
        </li>
        <li><a href="#">Blog</a>
        <ul class="subnav">
        <li><a href="#">Sub Nav Link</a></li>
        <li><a href="#">Sub Nav Link</a></li>
        <li><a href="#">Sub Nav Link</a></li>
        </ul>
        </li>
        <li><a href="#">Contact Me</a></li>
        <li><a href="#">Rss</a></li>
    </ul>

    Step2. 创建CSS

    div.examples_body_wrap {
         750px;
    	margin: 50px auto 0 auto;
    	clear: both;
    }
    div.examples_body_wrap h3 {
         color: #f9f66d;
         font-size: 130%;
    	 padding-bottom: 15px;
    	 margin-bottom: 15px;
    	 background: url(http://sunflowamedia.com/images/solid-line-news.gif) repeat-x bottom;
    }
    ul.topnav {
    	 710px;
    	padding: 0 0 200px 0;
    	float: left;
    	background: #222;
    	background: url(../images/topnav_bg.gif) repeat-x;
    }
    ul.topnav li {
    	float: left;
    	margin: 0;
    	padding: 0 10px 0 15px;
    	position: relative; /*--Declare X and Y axis base for sub navigation--*/
    	display: inline;
    }
    ul.topnav li a { 
    	padding: 10px 5px;
    	color: #fff;
    	display: block;
    	text-decoration: none;
    	float: left;
    }
    ul.topnav li a:hover {
    	background-color: #333;
    	-moz-border-radius: 3px; /*--CSS3 Rounded Corners--*/
    	-khtml-border-radius: 3px; /*--CSS3 Rounded Corners--*/
    	-webkit-border-radius: 3px; /*--CSS3 Rounded Corners--*/
    }
    ul.topnav li span { /*--Drop down trigger styles--*/
    	 17px;
    	height: 35px;
    	float: left;
    	background: url(../images/subnav_btn.gif) no-repeat center top;
    }
    ul.topnav li span.subhover { /*--Hover effect for trigger--*/
        background-position: center bottom; cursor: pointer;
    }   
    ul.topnav li ul.subnav {
    	 170px;
    	position: absolute; /*--Important - Keeps subnav from affecting main navigation flow--*/
    	left: 0; top: 35px;
    	background: #333;
    	margin: 0; padding: 0;
    	display: none;
    	float: left;
    	border: 1px solid #111;
    }
    ul.topnav li ul.subnav li{
    	 170px;
    	margin: 0; padding: 0;
    	border-top: 1px solid #252525; /*--Create bevel effect--*/
    	border-bottom: 1px solid #444; /*--Create bevel effect--*/
    	clear: both;
    }
    html ul.topnav li ul.subnav li a {
    	 145px;
    	float: left;
    	background-color: #333;
    	padding-left: 20px;
    	font-size: 0.9em;
    }
    html ul.topnav li ul.subnav li a:hover { /*--Hover effect for subnav links--*/
    	background-color: #222;
    }

    Step3. 插入jQuery和脚本包

    $(document).ready(function(){   
      
        $("ul.subnav").parent().append(""); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)   
      
        $("ul.topnav li span").mouseover(function() { //When trigger is clicked...   
      
            //Following events are applied to the subnav itself (moving subnav up and down)   
            $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click   
      
            $(this).parent().hover(function() {   
            }, function(){   
                $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up   
            });   
      
            //Following events are applied to the trigger (Hover events for the trigger)   
            }).hover(function() {   
                $(this).addClass("subhover"); //On hover over, add class "subhover"   
            }, function(){  //On Hover Out   
                $(this).removeClass("subhover"); //On hover out, remove class "subhover"   
        });   
      
    });

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

     *红字 Mouseover 改成 click 就是点击后下拉!!!

  • 相关阅读:
    STM32F0库函数初始化系列:进入STOP模式,外部中断唤醒
    STM32F0库函数初始化系列:ADC
    STM32F0库函数初始化系列:PWM输出
    VBS病毒实验
    AWVS漏洞扫描教程之扫描方式
    利用AWVS扫描Web漏洞
    命令执行漏洞靶场练习二
    命令执行漏洞靶场练习一
    CSRF POST型
    RainbowCrack彩虹表破解密码hash
  • 原文地址:https://www.cnblogs.com/leotan/p/1805920.html
Copyright © 2020-2023  润新知