Reputation: 4023
I want to expand the height of a container automatically to the multiply of 28px
. I have a pattern that can only be repeated vertically so I can't crop it at a height that is not a multiply of 28. For example if my container has a height of 400px
, I need to expand the height at 420px
so that the pattern repeats vertically and it's not cropped.
Any ideas as to the logic of the jQuery function I need to create?
Upvotes: 0
Views: 132
Reputation: 42746
var needsExpansion = jQuery("#mydiv").height()%28 > 0;
if( needsExpansion ) {
var newHeight = Math.ceil(jQuery("#mydiv").height()/28) * 28;
jQuery("#mydiv").height(newHeight);
}
Upvotes: 4
Reputation: 99544
Does this help?
var container = $('#container'), unit = 28, height = container.height();
(height % unit > 0) &&
container.height(Math.ceil(height / unit) * unit);
Upvotes: 6