Guest User

Untitled

a guest
May 20th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <!--
  2. Doing a typical display=none/block pushes the first TD's (sidebar) position to the right by 50-60px. This fix avoids the jump by applying 2 workarounds -
  3. 1. setting width via attribute instead of element.style.width
  4. 2. delivering different display properties to chrome/safari & everyone else
  5. -->
  6.  
  7. <script type="text/javascript">
  8. function toggleNavTree() {
  9. var td1 = document.getElementById('treenavtd');
  10. var td2 = document.getElementById('contenttd');
  11.  
  12. if (td1.className == 'treenavtd-hide') {
  13. td1.className = 'treenavtd-show'; // Avoid JS style.display & it's css specificity
  14. td1.setAttribute("width","18%"); // Seems TDs don't like style.Width (offset?)
  15. td2.setAttribute("width","82%"); // Instead TDs want all their Attributes
  16. }
  17. else {
  18. td1.className = 'treenavtd-hide';
  19. td1.setAttribute("width","0%"); // Helps in recalculating Table width :|
  20. td2.setAttribute("width","100%");
  21. }
  22. }
  23. </script>
  24.  
  25. <style type="text/css">
  26. // Avoid JS style.display & it's css specificity
  27. .treenavtd-hide {
  28. display: none;
  29. }
  30.  
  31. // Only Chrome since other browsers break with this
  32. body:nth-of-type(1) .treenavtd-show{
  33. display: table-cell;
  34. }
  35.  
  36. // All browsers except Chrome need this
  37. .treenavtd-show {
  38. display: inline;
  39. }
  40. </style>
  41.  
  42. <table width="99%" colspan="0" cellpadding="0" border="0">
  43. <tr>
  44. <td colspan="2"><a href="javascript:toggleNavTree()">Show/Hide</a></td>
  45. </tr>
  46. <tr>
  47. <td id="treenavtd" class="treenavtd-show" valign="top" align="left" width="18%">
  48. sidebar comes here
  49. </td>
  50. <td id="contenttd" valign="top" align="left" width="82%">
  51. content area comes here
  52. </td>
  53. </tr>
  54. </table>
Add Comment
Please, Sign In to add comment