Bootstrap Collapse accordion on hover

前端 未结 7 1967
轮回少年
轮回少年 2020-12-16 17:40

I\'m using Twitter\'s Bootstrap \'Collapse\' plug-in in a project I am working on. I have a simple accordion (setup as per the documentation), but I want to amend the defaul

7条回答
  •  离开以前
    2020-12-16 18:12

    I'm a bit late to the party, but for future googlers, I came up with a much simpler way of doing this.

    It's coffee script I'm afraid, but you should get the idea:

    $(".your-hoverable-object-class").mouseenter (e) ->
    $this = $(this)
    link = $this.find("a") #(assumes you only have one link)
    target = link.attr('data-target') || e.preventDefault() || (href = link.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') #strip for ie7
    unless $(target).hasClass('in')
      link.trigger('click') #Here's the money shot - just trigger the default functionality
    

    The rest of the code is setting up the variables - you might need to tweak this depending how you've set it up - and the last bit checks that the panel isn't already open before triggering the click again. Again - this works for my set up, but you can remove it if doesn't work for you.

提交回复
热议问题