Last active
August 29, 2015 14:19
-
-
Save kas-cor/72a9153081588172b3ea to your computer and use it in GitHub Desktop.
TableHeadClone
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
$(function() { | |
if ($(".headclone").length) { | |
var pos=$(".headclone").position(); | |
$(window).scroll(function() { | |
if ($(window).scrollTop()>pos.top) { | |
if (!$("#shapka").length) { | |
var h=0; | |
$(".headclone tr[class^=headclone-]").each(function() { | |
h+=$(this).height(); | |
}); | |
$("body").after("<div id=\"shapka\"></div>"); | |
$("#shapka").css({ | |
"position": "fixed", | |
"top": "0px", | |
"left": (pos.left+1-$(window).scrollLeft())+"px", | |
"width": $(".headclone").width(), | |
"height": h+1+"px", | |
"overflow": "hidden", | |
"box-shadow": "0 5px 15px 0 #aaa", | |
"display": "none" | |
}).html($(".headclone").clone()).fadeIn("fast"); | |
} else { | |
if ($("#shapka").css("display")!=="none") { | |
$("#shapka").css({"left": (pos.left+1-$(window).scrollLeft())+"px"}); | |
} else { | |
$("#shapka").fadeIn("fast"); | |
} | |
} | |
} else { | |
$("#shapka").fadeOut("fast"); | |
} | |
}); | |
$(window).resize(function() { | |
if ($("#shapka").length) { | |
$("#shapka").css({ | |
"left": (pos.left+1-$(window).scrollLeft())+"px", | |
"width": $(".headclone").width() | |
}); | |
} | |
}); | |
} | |
}); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Sample table head clone</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script type="text/javascript" src="script.js"></script> | |
</head> | |
<body> | |
<table border="1" style="border-collapse: collapse" width="100%" cellspacing="1" class="headclone"> | |
<tr align="center" bgcolor="#CCCCCC" class="headclone-1"> | |
<td>1</td> | |
<td>2</td> | |
<td>3</td> | |
<td>4</td> | |
<td>5</td> | |
</tr> | |
<tr align="center" bgcolor="#CCCCCC" class="headclone-2"> | |
<td>6</td> | |
<td>7</td> | |
<td>8</td> | |
<td>9</td> | |
<td>10</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
<tr> | |
<td>123</td> | |
<td>244</td> | |
<td>4563</td> | |
<td>23</td> | |
<td>645</td> | |
</tr> | |
<tr> | |
<td>fgfxd</td> | |
<td>xcv</td> | |
<td>ng</td> | |
<td>sdgf</td> | |
<td>x</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cloning of the table header
Example: