Skip to content

Instantly share code, notes, and snippets.

@NathanQ
Last active November 10, 2017 23:34
Show Gist options
  • Save NathanQ/f102620ebb92ebe36a33f8730b00fb49 to your computer and use it in GitHub Desktop.
Save NathanQ/f102620ebb92ebe36a33f8730b00fb49 to your computer and use it in GitHub Desktop.
Bootstrap accordion, tabs, and carousel helpers so the site looks and acts better
// scroll to heading of open collapse item so content is presented on the screen
$(function() {
$('.panel-collapse').on('shown.bs.collapse', function (e) {
var $panel = $(this).closest('.panel');
$('html,body').animate({
scrollTop: $panel.offset().top
}, 250);
});
});
// make things in a group the same height
function sameHeightenate(groupToSameHeight, sameHeighters) {
$(groupToSameHeight).each(function() {
var tallest = 0;
$(sameHeighters, $(groupToSameHeight)).each(function() {
tallest = tallest > $(this).height() ? tallest: $(this).height();
});
$(sameHeighters, $(groupToSameHeight)).each(function() {
$(this).height(tallest);
});
});
}
$(function() {
// example
sameHeightenate('.card-group.row', '.card');
sameHeightenate('.carousel.row', '.carousel-item');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment