Bootstrap 3 dropdown transition

后端 未结 2 1794
花落未央
花落未央 2021-01-03 00:13

Firstly here\'s the fiddle

Just a regular bootstrap dropdown, I made a few changes to css so that the dropdown appears on hover (instead of click) but how do I want

2条回答
  •  孤城傲影
    2021-01-03 00:39

    You can override the default style of display:none with display:block, since you're also using opacity:0 to hide the menu. Give the following CSS a try and see if that accomplishes what you need. I've updated the transition speed to make the effect more apparent.

    .dropdown .dropdown-menu{
        display: block;
        opacity: 0;
    
        -moz-transition:    all 1000ms ease;
        -webkit-transition: all 1000ms ease;
        -o-transition:      all 1000ms ease;
        -ms-transition:     all 1000ms ease;
        transition:         all 1000ms ease;
    }
    .dropdown:hover .dropdown-menu {
        display: block;
        opacity: 1;
    }
    

    Updated version of your fiddle: http://jsfiddle.net/pjej7o2m/1/

    Here's a jQuery script that might work as an alternative to hovering over the div (still using the css transition properties for opacity)

    $(function(){
      var $menu = $('.dropdown-menu');
    
      $('.dropdown-toggle').hover(
        function() {
          $menu.css('opacity',1);
        },
        function() {
          $menu.css('opacity',0);
        });
    })();
    

    Updated fiddle: http://jsfiddle.net/pjej7o2m/2/

提交回复
热议问题