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

              
                <body>
  <div id="root">
  </div>
</body>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Tenali+Ramakrishna&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Josefin+Sans&display=swap");
$borderRadius: 8px;
*,
*::after,
*::before {
  box-sizing: border-box;
  margin: 0;
}
button:active,
button:focus {
  outline: none;
}
html {
  padding: 0;
  margin: 0;
  font-size: 62.5%;
}
.slide {
  background: linear-gradient(to right, #bc4e9c, #f80759);
  color: white;
  position: relative;
  width: 80%;
  max-width: 900px;
  height: 70vh;
  min-height: 400px;
  margin: 2rem auto;
  border-radius: $borderRadius;
  &__title {
    font-size: 2.5rem;
    text-align: right;
    padding: 1rem 3rem;
    border-bottom: 4px solid white;
    font-family: "Tenali Ramakrishna", sans-serif;
    height: 20%;
    border-radius: $borderRadius $borderRadius 0 0;
    background-image: linear-gradient(45deg, #673ab7 30%, #ff5722 30%);
    letter-spacing: 1rem;
  }
  &__content {
    width: 100%;
    height: 85%;
    display: flex;
    justify-content: center;
    align-items: center;
    &--para {
      font-size: 2rem;
      text-align: justify;
      font-family: "Josefin Sans", sans-serif;
      letter-spacing: 0.2rem;
      line-height: 3rem;
      width: 80%;
    }
  }
  &__btn {
    border-radius: 50%;
    border: none;
    font-family: monospace;
    font-size: 3rem;
    width: 6rem;
    height: 6rem;
    background-color: blue;
    color: white;
    position: absolute;
    top: 50%;
    cursor: pointer;
    font-weight: bolder;
    transition: background-color 0.2s;

    &--next {
      right: 0;
      transform: translate(50%);
      &:hover {
        background-color: #f80759;
      }
    }
    &--prev {
      left: 0;
      transform: translateX(-50%);
      &:hover {
        background-color: #bc4e9c;
      }
    }
  }
}
.left {
  animation: leftAnimation 0.7s;
}
.fade {
  animation: fadeAnimation 0.7s;
}

@keyframes leftAnimation {
  from {
    transform: scale(0) translateX(-80vw);
  }

  to {
    transform: scale(1) translateX(0);
  }
}
@keyframes fadeAnimation {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media only screen and (max-width: 660px) {
  html {
    font-size: 50%;
  }
}

              
            
!

JS

              
                class Slide extends React.Component {
  constructor(props) {
    super(props);
    this.titleRef = React.createRef();
    this.contentRef = React.createRef();
  }
  handleAnimation = () => {
    const title = this.titleRef.current;
    const content = this.contentRef.current;
    title.classList.add("left");
    content.classList.add("fade");
  };
  handleNextClick = () => {
    this.handleAnimation();
    this.props.onNext();
  };
  handlePrevClick = () => {
    this.handleAnimation();
    this.props.onPrev();
  };

  componentDidUpdate() {
    const title = this.titleRef.current;
    const content = this.contentRef.current;
    setTimeout(() => {
      title.classList.remove("left");
      content.classList.remove("fade");
    }, 700);
  }
  render() {
    return (
      <div className="slide">
        <div className="slide__title">
          <h1 ref={this.titleRef}>{this.props.title}</h1>
        </div>
        <div className="slide__content" ref={this.contentRef}>
          <p className="slide__content--para">{this.props.children}</p>
        </div>
        <button
          className="slide__btn slide__btn--next"
          id="next"
          onClick={this.handleNextClick}
        >
          &gt;
        </button>
        <button
          className="slide__btn slide__btn--prev"
          id="prev"
          onClick={this.handlePrevClick}
        >
          &lt;
        </button>
      </div>
    );
  }
}
class SlideContainer extends React.Component {
  constructor(props) {
    super(props);
    document.addEventListener("keydown", (event) => {
      if (event.keyCode === 37) {
        this.prevHandler();
      } else if (event.keyCode === 39) {
        this.nextHandler();
      }
    });
    this.state = {
      slides: [
        {
          title: "Title 1",
          content:
            "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, "
        },
        {
          title: "Title 2",
          content:
            "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here',"
        },
        {
          title: "Title 3",
          content:
            "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum"
        }
      ],
      currentSlide: 0
    };
    this.nextHandler = this.nextHandler.bind(this);
    this.prevHandler = this.prevHandler.bind(this);
  }

  nextHandler() {
    this.setState((st) => ({
      ...st,
      currentSlide: (st.currentSlide + 1) % st.slides.length
    }));
  }
  prevHandler() {
    this.setState((st) => {
      let p = st.currentSlide - 1;
      if (p < 0) p = st.slides.length - 1;
      return {
        ...st,
        currentSlide: p
      };
    });
  }

  render() {
    const { currentSlide, slides } = this.state;
    return (
      <Slide
        title={slides[currentSlide].title}
        onNext={this.nextHandler}
        onPrev={this.prevHandler}
      >
        {slides[currentSlide].content}
      </Slide>
    );
  }
}

class App extends React.Component {
  render() {
    return <SlideContainer />;
  }
}

ReactDOM.render(<App />, document.getElementById("root"));

              
            
!
999px

Console