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 default functionality from on click to the on hover event.
Can anyone confirm the best way to achieve this?
Based on Cliff Seal's answer I suggest queueing animations to prevent
panel-collapse
from staying open whenmouseleave
occurs before thecollapse('show')
animation is finished.This doesn't make use of DRY coding, but I encountered
hover
eventsonload
when using a named function. Maybe someone can advise on this?You can copy the collapsible data-api straight from the plugins script and tweak it around to achieve the hover functionality. You can then place it inside your own script.js file and target the collapsible you want modified to open on hover instead of on click. Try this for example:
JS
This is a direct copy of the data-api block found on the plugin, i just replaced the
click
event withmouseenter
and also thecollapse
option, changed it toshow
instead.Demo: http://jsfiddle.net/um2q2/1/
to put it to work for bootstrap3 i made some changes
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:
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.
Add the following script
Add
hoverExpand
(or whatever you want to call it) to the element. See example belowThis is the simplest way to make that done on mouseover. Using plain javascript in angularJs.
Script
HTML code