Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <button id="button" class="accordion">Section 1</button>
<div class="panel">
  <p class="margin-b">Lorem ipsum...</p>
  
                        <div class="svg-line-container svg-desktop svg-line-trigger">
                                <svg width="1220" height="2599" viewBox="0 0 1220 2599">
                                    <path class="theLine" fill="none" stroke-width="1px" d="M1117.5 0C1117.5 96.5 1152.17 148.135 1181 205.5C1279 400.5 1154 520.5 1154 824.5C1154 1052.88 1280.5 1345.5 1051 1480C821.5 1614.5 580 1545.5 399 1510.5C217.999 1475.5 64.8917 1552.82 17.5003 1743C-59 2050 155.684 2219.49 272 2329C468.5 2514 660 2633 800.5 2589.5" stroke="#E3001A" />
                                </svg>
                            </div>
</div>

<button class="accordion">Section 2</button>
<div class="panel">
  <p>Lorem ipsum...</p>
</div>

<button class="accordion">Section 3</button>
<div class="panel">
  <p>Lorem ipsum...</p>
</div>
              
            
!

CSS

              
                /* Style the buttons that are used to open and close the accordion panel */
.accordion {
  background-color: #eee;
  color: #444;
  cursor: pointer;
  padding: 18px;
  width: 100%;
  text-align: left;
  border: none;
  outline: none;
  transition: 0.4s;
}

/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
.active, .accordion:hover {
  background-color: #ccc;
}

/* Style the accordion panel. Note: hidden by default */
.panel {
  padding: 0 18px;
  background-color: white;
  display: none;
  overflow: hidden;
  height:2000px;
  background-color:beige;
}

.panel.active {
  display: block;
}
              
            
!

JS

              
                console.clear();

gsap.registerPlugin(ScrollTrigger, DrawSVGPlugin);

let currentPanel;
let panels = gsap.utils.toArray(".panel");
let buttons = gsap.utils.toArray(".accordion");

panels.forEach((panel, i) => {
  let button = buttons[i];
  let isActive = false;
  let animation;

  function open() {
    console.log("open", i + 1);
    isActive = true;
    if (currentPanel && currentPanel !== panel) {
      currentPanel.close();
    }
    currentPanel = panel;
    panel.classList.add("active");

    if (i === 0) {
      animation = gsap
        .timeline({
          defaults: {
            duration: 10
          },
          scrollTrigger: {
            id: "svgLine",
            trigger: ".svg-line-trigger",
            scrub: 0.7,
            start: "top center-=30px",
            end: "bottom center",
            markers: true
          }
        })
        .fromTo(
          ".theLine",
          {
            drawSVG: 0
          },
          {
            drawSVG: true
          },
          0
        );
    }
  }

  function close() {
    console.log("close", i + 1);
    isActive = false;
    panel.classList.remove("active");
    animation && animation.kill();
  }

  button.addEventListener("click", () => {
    isActive ? close() : open();
  });

  panel.close = close;
});

// var acc = document.getElementsByClassName("accordion");
// var i;

// for (i = 0; i < acc.length; i++) {
//   acc[i].addEventListener("click", function() {
//     /* Toggle between adding and removing the "active" class,
//     to highlight the button that controls the panel */
//     this.classList.toggle("active");

//     /* Toggle between hiding and showing the active panel */
//     var panel = this.nextElementSibling;
//     if (panel.style.display === "block") {
//       panel.style.display = "none";
//     } else {
//       panel.style.display = "block";
//     }
//   });
// }

// gsap.registerPlugin(ScrollTrigger, DrawSVGPlugin);

// const button = document.getElementById('button');

// button.addEventListener('click', svgInit);

// function svgInit() {
// console.log("init success");

//   if (button.classList.contains('active')) {
// const svgLine = gsap.timeline({
//     defaults: {
//       duration: 10
//     },
//     scrollTrigger: {
//       id: "svgLine",
//       trigger: ".svg-line-trigger",
//       scrub: 0.7,
//       start: "top center-=30px",
//       end: 'bottom center',
//       markers: true
//     }
//   })
//   .from(".theLine", {
//     drawSVG: 0
//   }, 0)
// } else {
//   svgLine.ScrollTrigger.kill();
// }
// }

              
            
!
999px

Console