Skip to content

Instantly share code, notes, and snippets.

@tsmd
Created March 28, 2018 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsmd/8d5f6753a494efab2a1d4ad8236f144c to your computer and use it in GitHub Desktop.
Save tsmd/8d5f6753a494efab2a1d4ad8236f144c to your computer and use it in GitHub Desktop.
Basic idea of simple responsive-table
$.fn.responsiveTable = (function() {
var $window = $(window);
return function() {
var $el = this;
var $table = this.find('>table');
var onResize = function() {
var width = $table.outerWidth();
var height = $table.outerHeight();
var $parent = $el.parent();
var containerWidth = $parent.width();
var ratio = containerWidth / width;
if (ratio < 1) {
$el.height(height * ratio);
$table.css('transform', 'scale(' + ratio + ')');
} else {
$el.height('');
$table.css('transform', '');
}
};
$table.css('transformOrigin', '0 0');
$window.on('resize', onResize);
onResize();
};
}());
$(function() {
$('.responsive-table').responsiveTable();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment