Javascript 我想向jQuery和css中的菜单项添加一个子元素

Javascript 我想向jQuery和css中的菜单项添加一个子元素,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我用jQuery和CSS创建了一个菜单项。当我转到一个菜单项时,我想转到另一个子菜单项,如下图所示。我该怎么做 这是我的html标记 <link rel="stylesheet" href="css/style_j.css" type="text/css" media="screen"/> <div class="content"> <ul id="sdt_menu" class="sdt_menu"> <

我用jQuery和CSS创建了一个菜单项。当我转到一个菜单项时,我想转到另一个子菜单项,如下图所示。我该怎么做

这是我的html标记

<link rel="stylesheet" href="css/style_j.css" type="text/css" media="screen"/>
    <div class="content">
        <ul id="sdt_menu" class="sdt_menu">
            <li>
                <a href="#">
                    <img src="SlideDownBoxMenu2/images/2.jpg" alt=""/>
                    <span class="sdt_active"></span>
                    <span class="sdt_wrap">
                        <span class="sdt_link">Home</span>
                        <span class="sdt_descr">Home</span>
                    </span>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="SlideDownBoxMenu2/images/1.jpg" alt=""/>
                    <span class="sdt_active"></span>
                    <span class="sdt_wrap">
                        <span class="sdt_link">File Managements</span>
                        <span class="sdt_descr">File Managements</span>
                    </span>
                </a>
            <div class="sdt_box">
                        <a href="#"><img src="SlideDownBoxMenu2/images/1.jpg" alt=""/>
                    <span class="sdt_active"></span>
                    <span class="sdt_wrap">
                        <span class="sdt_link">Retention</span>
                        <span class="sdt_descr">Retention</span>
                    </span> </a>
                        <a href="#">Illustrations</a>
                        <a href="#">Photography</a>
                    <div class="sdt_box">

                        <a href="#">Retentionss </a>
                        <a href="#">Illustrations</a>
                        <a href="#">Photography</a>

                </div> 
                </div>
            </li>
            <li>
                <a href="#">
                    <img src="SlideDownBoxMenu2/images/1.jpg" alt=""/>
                    <span class="sdt_active"></span>
                    <span class="sdt_wrap">
                        <span class="sdt_link">Portfolio</span>
                        <span class="sdt_descr">My work</span>
                    </span>
                </a>
                <div class="sdt_box">
                        <a href="#">Websites</a>
                        <a href="#">Illustrations</a>
                        <a href="#">Photography</a>
                </div>
            </li>
            <li>
                <a href="#">
                    <img src="SlideDownBoxMenu2/images/1.jpg" alt=""/>
                    <span class="sdt_active"></span>
                    <span class="sdt_wrap">
                        <span class="sdt_link">Portfolio</span>
                        <span class="sdt_descr">My work</span>
                    </span>
                </a>
                <div class="sdt_box">
                        <a href="#">Websites</a>
                        <a href="#">Illustrations</a>
                        <a href="#">Photography</a>
                </div>
            </li>
            <li>
                <a href="#">
                    <img src="SlideDownBoxMenu2/images/1.jpg" alt=""/>
                    <span class="sdt_active"></span>
                    <span class="sdt_wrap">
                        <span class="sdt_link">Portfolio</span>
                        <span class="sdt_descr">My work</span>
                    </span>
                </a>
                <div class="sdt_box">
                        <a href="#">Websites</a>
                        <a href="#">Illustrations</a>
                        <a href="#">Photography</a>
                </div>
            </li>
        <li>
                <a href="#">
                    <img src="SlideDownBoxMenu2/images/1.jpg" alt=""/>
                    <span class="sdt_active"></span>
                    <span class="sdt_wrap">
                        <span class="sdt_link">Portfolio</span>
                        <span class="sdt_descr">My work</span>
                    </span>
                </a>
                <div class="sdt_box">
                        <a href="#">Websites</a>
                        <a href="#">Illustrations</a>
                        <a href="#">Photography</a>
                </div>
            </li>
            <li>
                <a href="#">
                    <img src="SlideDownBoxMenu2/images/6.jpg" alt=""/>
                    <span class="sdt_active"></span>
                    <span class="sdt_wrap">
                        <span class="sdt_link">Projects</span>
                        <span class="sdt_descr">I like to code</span>
                    </span>
                </a>
                <div class="sdt_box">
                    <a href="#">Job Board Website</a>
                    <a href="#">Shopping Cart</a>
                    <a href="#">Interactive Maps</a>
                </div>
            </li>
        </ul>
    </div>
<div>
    <span class="reference">

    </span>
    </div>
以下是我使用jQuery编写的Javascript代码:

   <!-- The JavaScript -->

        <script type="text/javascript">
            $(function() {
                /**
                * for each menu element, on mouseenter, 
                * we enlarge the image, and show both sdt_active span and 
                * sdt_wrap span. If the element has a sub menu (sdt_box),
                * then we slide it - if the element is the last one in the menu
                * we slide it to the left, otherwise to the right
                */
                $('#sdt_menu > li').bind('mouseenter',function(){
                    var $elem = $(this);
                    $elem.find('img')
                         .stop(true)
                         .animate({
                            'width':'138px',
                            'height':'57px',
                            'left':'0px'
                         },400,'easeOutBack')
                         .andSelf()
                         .find('.sdt_wrap')
                         .stop(true)
                         .animate({'top':'140px'},500,'easeOutBack')
                         .andSelf()
                         .find('.sdt_active')
                         .stop(true)
                         .animate({'height':'138px'},300,function(){
                        var $sub_menu = $elem.find('.sdt_box');
                        if($sub_menu.length){
                            var left = '138px';
                            if($elem.parent().children().length == $elem.index()+1)
                                left = '-138px';
                            $sub_menu.show().animate({'left':left},200);
                        }   
                    });
                }).bind('mouseleave',function(){
                    var $elem = $(this);
                    var $sub_menu = $elem.find('.sdt_box');
                    if($sub_menu.length)
                        $sub_menu.hide().css('left','0px');

                    $elem.find('.sdt_active')
                         .stop(true)
                         .animate({'height':'0px'},300)
                         .andSelf().find('img')
                         .stop(true)
                         .animate({
                            'width':'0px',
                            'height':'0px',
                            'left':'85px'},400)
                         .andSelf()
                         .find('.sdt_wrap')
                         .stop(true)
                         .animate({'top':'25px'},500);
                });
            });
        </script>

$(函数(){
/**
*对于鼠标指针上的每个菜单元素,
*我们放大图像,同时显示sdt_活动范围和
*sdt_包装跨度。如果元素有子菜单(sdt_框),
*然后我们滑动它-如果元素是菜单中的最后一个元素
*我们向左滑动,否则向右滑动
*/
$('sdt_menu>li').bind('mouseenter',function(){
变量$elem=$(本);
$elem.find('img'))
.停止(正确)
.制作动画({
“宽度”:“138px”,
“高度”:“57px”,
“左”:“0px”
},400,'easeOutBack')
.andSelf()
.find(“.sdt_wrap”)
.停止(正确)
.animate({'top':'140px'},500,'easeOutBack')
.andSelf()
.find(“.sdt_活动”)
.停止(正确)
.animate({'height':'138px'},300,function(){
var$sub_menu=$elem.find('.sdt_框');
如果($sub_menu.length){
左变量='138px';
如果($elem.parent().children().length==$elem.index()+1)
左='-138px';
$sub_menu.show().animate({'left':left},200);
}   
});
}).bind('mouseleave',function(){
变量$elem=$(本);
var$sub_menu=$elem.find('.sdt_框');
如果($sub_menu.length)
$sub_menu.hide().css('left','0px');
$elem.find(“.sdt\u活动”)
.停止(正确)
.animate({'height':'0px'},300)
.andSelf().find('img'))
.停止(正确)
.制作动画({
“宽度”:“0px”,
“高度”:“0px”,
'左':'85px'},400)
.andSelf()
.find(“.sdt_wrap”)
.停止(正确)
.animate({'top':'25px'},500);
});
});

为什么不将所有内容组织到一个列表中?您好,现在请检查并执行以下操作
   <!-- The JavaScript -->

        <script type="text/javascript">
            $(function() {
                /**
                * for each menu element, on mouseenter, 
                * we enlarge the image, and show both sdt_active span and 
                * sdt_wrap span. If the element has a sub menu (sdt_box),
                * then we slide it - if the element is the last one in the menu
                * we slide it to the left, otherwise to the right
                */
                $('#sdt_menu > li').bind('mouseenter',function(){
                    var $elem = $(this);
                    $elem.find('img')
                         .stop(true)
                         .animate({
                            'width':'138px',
                            'height':'57px',
                            'left':'0px'
                         },400,'easeOutBack')
                         .andSelf()
                         .find('.sdt_wrap')
                         .stop(true)
                         .animate({'top':'140px'},500,'easeOutBack')
                         .andSelf()
                         .find('.sdt_active')
                         .stop(true)
                         .animate({'height':'138px'},300,function(){
                        var $sub_menu = $elem.find('.sdt_box');
                        if($sub_menu.length){
                            var left = '138px';
                            if($elem.parent().children().length == $elem.index()+1)
                                left = '-138px';
                            $sub_menu.show().animate({'left':left},200);
                        }   
                    });
                }).bind('mouseleave',function(){
                    var $elem = $(this);
                    var $sub_menu = $elem.find('.sdt_box');
                    if($sub_menu.length)
                        $sub_menu.hide().css('left','0px');

                    $elem.find('.sdt_active')
                         .stop(true)
                         .animate({'height':'0px'},300)
                         .andSelf().find('img')
                         .stop(true)
                         .animate({
                            'width':'0px',
                            'height':'0px',
                            'left':'85px'},400)
                         .andSelf()
                         .find('.sdt_wrap')
                         .stop(true)
                         .animate({'top':'25px'},500);
                });
            });
        </script>