当我放入幻灯片放映时,向下滑动框菜单停止工作

时间:2012-11-17 20:56:01

标签: javascript jquery

我是网页设计的新手,真的需要一些课程项目的帮助。我有一个滑动导航,我正在使用http://tympanus.net/codrops/2010/07/16/slide-down-box-menu/

中的以下Javascript
<!-- The JavaScript -->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
    <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':'170px',
                        'height':'170px',
                        'left':'0px'
                     },400,'easeOutBack')
                     .andSelf()
                     .find('.sdt_wrap')
                     .stop(true)
                     .animate({'top':'140px'},500,'easeOutBack')
                     .andSelf()
                     .find('.sdt_active')
                     .stop(true)
                     .animate({'height':'170px'},300,function(){
                    var $sub_menu = $elem.find('.sdt_box');
                    if($sub_menu.length){
                        var left = '170px';
                        if($elem.parent().children().length == $elem.index()+1)
                            left = '-170px';
                        $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>

当我尝试在页面上放置幻灯片时,导航停止工作。我尝试了几个幻灯片,与所有这些幻灯片存在某种冲突。我试图使用的是来自http://www.jacklmoore.com/monte

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

你正在调用动画并一次多次停止。您可以采用两种方法来构建队列系统(jQuery does have one),或者使用提供的回调(在函数执行后运行的函数)。

要清楚,像这样的代码一次全部运行:

a.animate1()
b.animate2() //animate2 doesn't wait for animate 1, thus, use of callbacks and/or queues.

作为旁注,看看你是否可以通过使用函数来减少已经使用了大量剪切+粘贴的代码部分。祝这个项目好运!