Guest User

Untitled

a guest
May 20th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Document</title>
  6. </head>
  7. <body>
  8. <table>
  9. <tr>
  10. <th class="scrollOption_parent">タイトル<span class="scrollOption">全表示</span></th>
  11. <td>
  12. <div class="smartCell">
  13. <?php for($i = 0; $i < 100; $i++): ?>
  14. <span>あいうえお<?= $i; ?></span>
  15. <?php endfor; ?>
  16. </div>
  17. </td>
  18. </tr>
  19. <tr>
  20. <th class="scrollOption_parent">タイトル<span class="scrollOption">全表示</span></th>
  21. <td>
  22. <div class="smartCell">
  23. <?php for($i = 0; $i < 100; $i++): ?>
  24. <span>あいうえお<?= $i; ?></span>
  25. <?php endfor; ?>
  26. </div>
  27. </td>
  28. </tr>
  29. </table>
  30. <script>
  31. ;(function() {
  32. window.addEventListener('DOMContentLoaded', function() {
  33. smartCell('scrollOption', 'smartCell');
  34. console.log(getCookieVal('scrollOptionDisplay_1'));
  35.  
  36. }, false);
  37.  
  38. function smartCell(triger, target) {
  39. console.dir(document.cookie);
  40. var scrollOptions = document.getElementsByClassName(triger),
  41. smartCells = document.getElementsByClassName(target);
  42. for(var i = 0, l = scrollOptions.length; i < l; i++) {
  43. (function(j) {
  44. scrollOptions[j].addEventListener('click', function() {
  45. smartCells[j].classList.toggle('smartCellToggle');
  46. if(this.innerText === '省表示') {
  47. this.innerText = '全表示';
  48. document.cookie = 'scrollOptionDisplay_' + j + '=short';
  49. } else {
  50. this.innerText = '省表示';
  51. document.cookie = 'scrollOptionDisplay_' + j + '=wide';
  52. }
  53. }, false);
  54. })(i);
  55. }
  56.  
  57. var optionCookie = getCookieVal('scrollOptionDisplay_0'),
  58. campaignCookie = getCookieVal('scrollOptionDisplay_1');
  59. if(optionCookie === 'wide') {
  60. smartCells[0].classList.toggle('smartCellToggle');
  61. scrollOptions[0].innerText = '省表示';
  62. }
  63. if(campaignCookie === 'wide') {
  64. smartCells[1].classList.toggle('smartCellToggle');
  65. scrollOptions[1].innerText = '省表示';
  66. }
  67. }
  68.  
  69. function getCookieVal(name) {
  70. var result = null,
  71. cookieName = name + '=',
  72. allcookies = document.cookie,
  73. position = allcookies.indexOf(cookieName);
  74. if(position != -1) {
  75. var startIndex = position + cookieName.length,
  76. endIndex = allcookies.indexOf( ';', startIndex);
  77. if(endIndex == -1) {
  78. endIndex = allcookies.length;
  79. }
  80. result = decodeURIComponent(allcookies.substring(startIndex, endIndex));
  81. }
  82. return result;
  83. }
  84.  
  85. })();
  86. </script>
  87. <style>
  88. table {
  89. border-collapse: collapse;
  90. }
  91. th {
  92. width: 4em;
  93. }
  94. td,
  95. th {
  96. border: 1px solid #ccc;
  97. }
  98. .smartCell {
  99. height: 200px;
  100. overflow-y: scroll;
  101. }
  102. .scrollOption_parent {
  103. position: relative;
  104. }
  105. .scrollOption {
  106. position: absolute;
  107. right: 0;
  108. bottom: 0;
  109. left: 0;
  110. margin: 0 auto;
  111. cursor: pointer;
  112. }
  113. .smartCellToggle {
  114. height: initial;
  115. overflow-y: initial;
  116. }
  117. </style>
  118. </body>
  119. </html>
Add Comment
Please, Sign In to add comment