How to implement a Navbar Dropdown Hover in Bootstrap v4?

前端 未结 20 938
猫巷女王i
猫巷女王i 2020-12-02 05:40

I am a bit confused on the new bootstrap version since they changed dropdown menus to divs:

20条回答
  •  醉梦人生
    2020-12-02 06:42

    Andrei's "complete" jQuery+CSS solution has the right intent, but it's verbose and still incomplete. Incomplete because while it probably covers all the necessary DOM changes, it's missing the firing of custom events. Verbose because it's wheel-reinventing when Bootstrap already provides the dropdown() method, which does everything.

    So the correct, DRY solution, which does not rely on the CSS hack often repeated among other answers, is just jQuery:

    $('body').on('mouseover mouseout', '.dropdown', function(e) {
        $(e.target).dropdown('toggle');
    });
    

提交回复
热议问题