Created
April 7, 2015 13:52
-
-
Save zhy0216/ccde00660dbf645d7963 to your computer and use it in GitHub Desktop.
responsive table
This file contains hidden or 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
$(function(){ | |
var threadNames = []; | |
$('th').each(function(i){ | |
threadNames.push($(this).html()); | |
}); | |
var style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = "@media "+ | |
"only screen and (max-width:760px),(min-device-width:768px) and (max-device-width:1024px){table,thead,tbody,th,td,tr{display:block}thead tr{position:absolute;top:-9999px;left:-9999px}tr{border:1px solid #ccc}td{border:none;border-bottom:1px solid #eee;position:relative;padding-left:50%!important}td:before{position:absolute;top:6px;left:6px;width:45%;padding-right:10px;white-space:nowrap;text-align:left}"; | |
for(var i=1; i <= threadNames.length; i++){ | |
style.innerHTML += 'td:nth-of-type('+ i + '):before { content: "'+ threadNames[i-1] + '"; }'; | |
} | |
style.innerHTML += "}" | |
document.getElementsByTagName('head')[0].appendChild(style); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment