Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. /* Style the element that is used to open and close the accordion class */
  2. div.accordion {
  3. background-color: #fff;
  4. color: #444;
  5. cursor: pointer;
  6. padding: 0px;
  7. width: 100%;
  8. text-align: left;
  9. border: none;
  10. outline: none;
  11. transition: 0.4s;
  12. margin-bottom:10px;
  13. opacity: 0.70;
  14. filter: alpha(opacity=70);
  15. }
  16.  
  17. /* Add a background color to the accordion if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
  18. div.accordion.active, div.accordion:hover {
  19. background: rgb(255,255,255);
  20. background: linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(232,231,222,1) 50%, rgba(255,255,255,1) 100%);
  21. opacity: 1;
  22. filter: alpha(opacity=100);
  23. }
  24.  
  25. /* Style the element that is used for the panel class */
  26.  
  27. div.panel {
  28. padding: 0 18px;
  29. background-color: white;
  30. max-height: 0;
  31. overflow: hidden;
  32. transition: 0.4s ease-in-out;
  33. opacity: 0;
  34. margin-bottom:10px;
  35. }
  36.  
  37. div.panel.show {
  38. opacity: 1;
  39. max-height: 500px; /* Whatever you like, as long as its more than the height of the content (on all screen sizes) */
  40. }
  41.  
  42. <script>
  43. document.addEventListener("DOMContentLoaded", function(event) {
  44. var acc = document.getElementsByClassName("accordion");
  45. var panel = document.getElementsByClassName('panel');
  46.  
  47. for (var i = 0; i < acc.length; i++) {
  48. acc[i].onclick = function() {
  49. var setClasses = !this.classList.contains('active');
  50. setClass(acc, 'active', 'remove');
  51. setClass(panel, 'show', 'remove');
  52.  
  53. if (setClasses) {
  54. this.classList.toggle("active");
  55. this.nextElementSibling.classList.toggle("show");
  56. }
  57. }
  58. }
  59.  
  60. function setClass(els, className, fnName) {
  61. for (var i = 0; i < els.length; i++) {
  62. els[i].classList[fnName](className);
  63. }
  64. }
  65.  
  66. });
  67. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement