soundasleep / jquery-dropdown

Bootstrap-style dropdowns with some added features and no dependencies.
Other
767 stars 268 forks source link

Match width of dropdown to parent element #14

Closed aduro closed 11 years ago

aduro commented 11 years ago

I added some code to the css that gets appended to the dropdown. In my case I am using this on a button class and want the dropdown to match the width of the parent element.

dropdown
.css({
width: trigger.outerWidth(),
left: dropdown.hasClass('anchor-right') ?
trigger.offset().left - (dropdown.outerWidth() - trigger.outerWidth()) + hOffset : trigger.offset().left + hOffset,
top: trigger.offset().top + trigger.outerHeight() + vOffset
})
.show();

Not being particularly great at javascript I couldn't figure out how to only trigger the width if the link has a class of "button" realizing that it would be better to scope the width change only to the elements it is needed on.

Hope it helps out anyone else that is trying to do the same thing.