Guest User

Untitled

a guest
Feb 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. (function($) {
  2. /**
  3. * .matchHeight()
  4. * - match heights of multiple columns that use css layout with floating elements
  5. */
  6. $.fn.matchHeight = function(options) {
  7. // set the containing element and set elements used as columns
  8. var defaults = {
  9. container : '.main',
  10. columns : 'div',
  11. excluded : '.dontChangeThis, .dontChangeThat',
  12. fixed : 200
  13. };
  14. var opts = $.extend(defaults, options);
  15. return this.each(function() {
  16. var _ = { self : $(this) };
  17. _.px = {};
  18. _.cols = $(opts.container+' > '+opts.columns);
  19. _.cols.each(function(index) {
  20. _.px.index = $(this).height();
  21. if ($(opts.excluded).length>0) {
  22. _.colheight = opts.fixed;
  23. return;
  24. } else {
  25. if (index < 1) {
  26. _.colheight = _.px.index;
  27. } else {
  28. if (_.px.index > _.colheight) {
  29. _.colheight = _.px.index;
  30. }
  31. }
  32. }
  33. }).each(function(index) {
  34. $(this).css({ height : _.colheight });
  35. });
  36. });
  37. };
  38. })(jQuery);
  39.  
  40. //
  41. // Call the plugin on a containing layout element with multiple columns
  42. //
  43.  
  44. /**
  45. * Stuff to do as soon as the DOM is ready
  46. * - enable plugin behavior(s)
  47. */
  48. $(function() {
  49. $('.main-container')matchHeight({
  50. container : '.main',
  51. columns : 'div.cols',
  52. excluded : 'body.page2, div.noColumns',
  53. fixed : 200
  54. });
  55. // or us the defaults
  56. // $('.container').matchHeight();
  57. });
Add Comment
Please, Sign In to add comment