Created
March 28, 2018 13:19
-
-
Save tsmd/8d5f6753a494efab2a1d4ad8236f144c to your computer and use it in GitHub Desktop.
Basic idea of simple responsive-table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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