Jquery Superfish菜单-如何向上滑动?

发布于 2024-08-29 19:22:54 字数 1072 浏览 2 评论 0原文

这是 superfish 菜单插件的 jquery 代码(经过我的一些修改)。我希望添加一个效果(通过 superfish 或偶然),使子菜单在鼠标移开时向上滑动(就像当您将鼠标悬停在菜单顶部时它们向下滑动一样)。

jQuery("ul.sf-menu").supersubs({ 
        minWidth:    12,                                // minimum width of sub-menus in em units 
        maxWidth:    27,                                // maximum width of sub-menus in em units 
        extraWidth:  1                                  // extra width can ensure lines don't sometimes turn over 
                                                        // due to slight rounding differences and font-family 
    }).superfish({ 
        delay:       700,                               // delay on mouseout 
        animation:   {opacity:'show',height:'show'},    // fade-in and slide-down animation 
        speed:       'fast',                            // faster animation speed 
        autoArrows:  true,                             // disable generation of arrow mark-up 
        dropShadows: false                             // disable drop shadows
    }); 

This is the jquery code for superfish menu plugin (after some revisions of mine). I'm looking to add an effect (either through superfish or adventitiously) that would cause the submenus to slide up on mouseout (just as they slide down when you hover a menu-top).

jQuery("ul.sf-menu").supersubs({ 
        minWidth:    12,                                // minimum width of sub-menus in em units 
        maxWidth:    27,                                // maximum width of sub-menus in em units 
        extraWidth:  1                                  // extra width can ensure lines don't sometimes turn over 
                                                        // due to slight rounding differences and font-family 
    }).superfish({ 
        delay:       700,                               // delay on mouseout 
        animation:   {opacity:'show',height:'show'},    // fade-in and slide-down animation 
        speed:       'fast',                            // faster animation speed 
        autoArrows:  true,                             // disable generation of arrow mark-up 
        dropShadows: false                             // disable drop shadows
    }); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夜空下最亮的亮点 2024-09-05 19:22:55

但是,您可以通过破解代码来使其工作。我会提交补丁,但代码开发不是公开托管的。

hideSuperfishUl : function(){
            var o = sf.op,
                not = (o.retainPath===true) ? o.$path : '';
            o.retainPath = false;
            var $ul = $(['li.',o.hoverClass].join(''),this)
                .add(this)
                .not(not)
                // .removeClass(o.hoverClass)
                .find('>ul').animate( {opacity: 'hide', height: 'hide'}, o.speed, function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
            o.onHide.call($ul);
            return this;
        },

However, you can make it work by hacking the code. I would submit a patch but the code development isn't hosted publicly.

hideSuperfishUl : function(){
            var o = sf.op,
                not = (o.retainPath===true) ? o.$path : '';
            o.retainPath = false;
            var $ul = $(['li.',o.hoverClass].join(''),this)
                .add(this)
                .not(not)
                // .removeClass(o.hoverClass)
                .find('>ul').animate( {opacity: 'hide', height: 'hide'}, o.speed, function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
            o.onHide.call($ul);
            return this;
        },
沉鱼一梦 2024-09-05 19:22:55

实现隐藏 superfish 任务的正确方法与显示相同:

hideSuperfishUl : function(){
        var o = sf.op,
        not = (o.retainPath===true) ? o.$path : '';
        o.retainPath = false;
        //hacked code by Farhan Wazir (Seejee)
    var $ul_p1 = $(['li.',o.hoverClass].join(''),this).add(this).not(not);
    var $ul_p2 = $ul_p1.find('>ul');
    var $ul = $ul_p2.animate( {opacity: 'hide', height: 'hide'}, o.speed,
        function(){ return $ul_p1.removeClass(o.hoverClass).find('>ul').css({top: '-99999em'}).addClass('sf-hidden');});
        o.onHide.call($ul);
        return this;
},

Correct way to achieve task of hiding superfish same as showing:

hideSuperfishUl : function(){
        var o = sf.op,
        not = (o.retainPath===true) ? o.$path : '';
        o.retainPath = false;
        //hacked code by Farhan Wazir (Seejee)
    var $ul_p1 = $(['li.',o.hoverClass].join(''),this).add(this).not(not);
    var $ul_p2 = $ul_p1.find('>ul');
    var $ul = $ul_p2.animate( {opacity: 'hide', height: 'hide'}, o.speed,
        function(){ return $ul_p1.removeClass(o.hoverClass).find('>ul').css({top: '-99999em'}).addClass('sf-hidden');});
        o.onHide.call($ul);
        return this;
},
荒人说梦 2024-09-05 19:22:54

目前你不能。直接从代码来看:

hideSuperfishUl : function(){
  var o = sf.op,
    not = (o.retainPath===true) ? o.$path : '';
  o.retainPath = false;
  var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
      .find('>ul').hide().css('visibility','hidden');
  o.onHide.call($ul);
  return this;
},
showSuperfishUl : function(){
  var o = sf.op,
    sh = sf.c.shadowClass+'-off',
    $ul = this.addClass(o.hoverClass)
      .find('>ul:hidden').css('visibility','visible');
  sf.IE7fix.call($ul);
  o.onBeforeShow.call($ul);
  $ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
  return this;
}

您可以看到 show 函数调用 animate(),而 hide 函数只调用 hide()。

You can't, currently. Straight from the code:

hideSuperfishUl : function(){
  var o = sf.op,
    not = (o.retainPath===true) ? o.$path : '';
  o.retainPath = false;
  var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
      .find('>ul').hide().css('visibility','hidden');
  o.onHide.call($ul);
  return this;
},
showSuperfishUl : function(){
  var o = sf.op,
    sh = sf.c.shadowClass+'-off',
    $ul = this.addClass(o.hoverClass)
      .find('>ul:hidden').css('visibility','visible');
  sf.IE7fix.call($ul);
  o.onBeforeShow.call($ul);
  $ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
  return this;
}

You can see that the show function calls animate(), whereas the hide function simply calls hide().

何以畏孤独 2024-09-05 19:22:54

我不确定旧版本的 superfish 但现在很容易完成(向下滑动和向上滑动) - 就像这样

$('...').superfish({
    hoverClass:    'sfhover',          // the class applied to hovered list items
    animation:     {height: "show", marginTop: "show", marginBottom: "show", paddingTop: "show", paddingBottom: "show"},   // an object equivalent to first parameter of jQuery’s .animate() method. Used to animate the submenu open
    animationOut:  {height: "hide", marginTop: "hide", marginBottom: "hide", paddingTop: "hide", paddingBottom: "hide"},   // an object equivalent to first parameter of jQuery’s .animate() method Used to animate the submenu closed
}); 

I'm not sure about the older versions of superfish but this is now easily accomplished (slidedown, and slideup) - like so

$('...').superfish({
    hoverClass:    'sfhover',          // the class applied to hovered list items
    animation:     {height: "show", marginTop: "show", marginBottom: "show", paddingTop: "show", paddingBottom: "show"},   // an object equivalent to first parameter of jQuery’s .animate() method. Used to animate the submenu open
    animationOut:  {height: "hide", marginTop: "hide", marginBottom: "hide", paddingTop: "hide", paddingBottom: "hide"},   // an object equivalent to first parameter of jQuery’s .animate() method Used to animate the submenu closed
}); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文