Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <div class="container">
  2. <span class="btn btn-toggle">
  3. Clique
  4. </span>
  5. <div class="thumb item-toggle test1" id="test1">
  6.  
  7. </div>
  8. </div>
  9. <div class="container">
  10. <span class="btn btn-toggle">
  11. Clique
  12. </span>
  13. <div class="thumb item-toggle test2" id="teste2">
  14.  
  15. </div>
  16. </div>
  17.  
  18.  
  19. *{
  20. margin: 0;
  21. padding: 0;
  22. }
  23. .container{
  24. padding: 50px;
  25. }
  26. .thumb{
  27. background-color: blue;
  28. width: 100px;
  29. height: 100px;
  30. display: block;
  31. }
  32. .btn{
  33. padding: 5px 15px;
  34. color: #fff;
  35. background-color: green;
  36. cursor: pointer;
  37. margin-bottom: 10px;
  38. display: inline-block;
  39. }
  40.  
  41. .item-toggle {
  42. max-height:0; overflow:hidden; transition: 500ms;
  43. }
  44. .active-toggle {
  45. max-height:100vh; overflow:inerght; transition: 500ms;
  46. }
  47.  
  48.  
  49. Array.from(document.querySelectorAll(".btn-toggle")).forEach(function(el){
  50. el.onclick= function(e) {
  51.  
  52. console.log(el.nextElementSibling);
  53. slideToggle(el.nextElementSibling);
  54.  
  55. }
  56. });
  57.  
  58. /*
  59. let toggleItem = document.querySelectorAll(".item-toggle");
  60.  
  61. for(i = 0; i < toggleItem.length; i++){
  62. //toggleItem[i].style.visibility='hidden';
  63. toggleItem[i].setAttribute("style", "max-height:0; overflow:hidden");
  64.  
  65. }
  66. */
  67.  
  68.  
  69. function slideToggle(el, className){
  70. console.log(el);
  71. el.classList.toggle('active-toggle');
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement