Yii Framework Forum: Dropdown On Hover For Bootstrap Navbar - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Dropdown On Hover For Bootstrap Navbar Rate Topic: -----

#1 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 671
  • Joined: 12-September 10
  • Location:Austria

Posted 12 April 2014 - 03:47 PM

I was looking for a solution that the items of a bootstrap navbar will dropdown on mouse over.
And the items that opens a submenu should work onClick if the url is not '#'.

I have found a lot of discussion/snippets, but only a few worked for me.

The quintessence - maybe it's useful for one of you:


    /**
     * A script that modifies bootstrap navbar to dropdown on mouse over.
     * And a parent of a submenu will be responsive to onClick if the assigned url is not '#'.
     */
    public static function registerDropDownOnHoverScript($slideDown=300,$slideUp=200,$position=CClientScript::POS_READY)
    {
        $script = <<<EOP
                $('.navbar li.dropdown').hover(
                     function() { $(this).find('.dropdown-menu').first().stop(true, true).slideDown($slideDown); },
                     function() { $(this).find('.dropdown-menu').first().stop(true, true).slideUp($slideUp); }
                     );
                $('.navbar li.dropdown > a').click(function(){ if(this.href) location.href = this.href; });
                $('.navbar li.dropdown-submenu > a').click(function(){ if(this.href) location.href = this.href; });
EOP;

        $css = '.dropdown-menu{margin: 0 2px 0 0;}'; //correction of the bottom margin

        Yii::app()->getClientScript()->registerScript('hover_navbartop',$script,$position);
        Yii::app()->getClientScript()->registerCss('hover_navbartop_css',$css);
    }


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users