Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                #root
              
            
!

CSS

              
                @import url(//db.onlinewebfonts.com/c/ae3d2d36962063f5a2ffb4cbd6003790?family=LampionW00-Regular);
* {
  margin: 0;
  padding: 0;
}
body {
  font-family: "LampionW00-Regular";
  letter-spacing: .2rem;
}
p {
  word-break: break-all;
}
.flex-center {
  display: flex;
  align-self: flex-start;
  align-content: center;
  align-items: center;
  justify-content: center;
}
.layout-left {
  .album {
    margin-left: -30rem;
  }
  .section {
    margin-right: -30rem;
  }
}
.layout-right {
  .album {
    margin-right: -30rem;
  }
  .section {
    margin-left: -30rem;
  }
}
.slider {
  position: relative;
  width: 100vw;
  height: auto;
  background: #fff;
  .flex-center;
  flex-flow: wrap row;
  .container:nth-child(2n) {
    .layout-left;
  }
  .container:nth-child(2n+1) {
    .layout-right;
  }
  .container {
    box-shadow: 0 0 2.2rem RGBA(110, 110, 110, 1.00);
    background: #fff;
    .inner-container {
        position: relative;
        width: 100vw;
        min-height: 100vh;
        .flex-center;
        flex-flow: wrap column;
        .sliding-block {
        position: relative;
        width: 100vw;
        min-height: 100vh;
        .flex-center;
        flex-flow: wrap column;
        }
        .static-block {
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100vw;
        min-height: 100vh;
        .flex-center;
        flex-flow: wrap column;
        &.pausing {
            position: fixed;
            top: 0;
            left: 0;
        }
        .section {
            width: 22rem;
            padding: 1rem;
            font-size: 1.2rem;
            .title {
            font-family: "LampionW00-Regular";
            letter-spacing: .3rem;
            font-size: 2.4rem;
            font-weight: bolder;
            line-height: 4rem;
            padding-left: 1rem;
            text-shadow: 0 -1.2px 0 #333,
                0 3px 4px rgba(0,0,0,.4),
                0 4px 5px rgba(0,0,0,.15),
                0 5px 5px rgba(0,0,0,.18),
                0 5px 5px rgba(0,0,0,.21);
            }
        }
        }
        .album {
        padding: 1rem;
        padding-top: 10rem;
        .album-item {
            position: relative;
            padding: 1rem;
            margin: 4rem;
            background: #fff;
            box-shadow:0 .1rem .4rem rgba(120, 120, 120, 0.3), 0 0 2rem rgba(120, 120, 120, 0.1) inset;
            &:before, &:after {
            position: absolute;
            content: "";
            top: 25px;
            left: 20px;
            bottom: 150px;
            width: 80%;
            z-index: -1;
            -webkit-transform: rotate(-6deg);
            -moz-transform: rotate(-6deg);
            transform: rotate(-6deg);
            }
            &:before {
            box-shadow: 10px -10px 30px 15px RGBA(120, 120, 120, .3);
            }
            &:after {
            -webkit-transform: rotate(7deg);
            -moz-transform: rotate(7deg);
            transform: rotate(7deg);
            bottom: 25px;
            top: auto;
            box-shadow: 10px 10px 30px 15px RGBA(120, 120, 120, .3);
            }
            .image-wrapper {
            width: 28rem;
            height: 28rem;
            position: relative;
            .image {
                width: 28rem;
                height: 28rem;
                position: absolute;
                top: 0;
                left: 0;
                opacity: 1;
                background-size: cover;
                transition: all 1s ease; 
                &.hidden {
                    opacity: 0;
                }
            }
            }
        }
        }
        &:last-child .album {
            padding-top: 0;
        }
      
        .content {
        width: 90vw;
        min-height: 80vh;
        background-size: cover;
        }
    }
    &.current {
        .sliding-block, .static-block {
            position: fixed;
            top: 0;
            left: 0;
        }
    }
  }
  .header {
    width: 100vw;
    height: 100vh;
    position: relative;
    .flex-center;
    background: #fff;
    z-index: 130;
    background-size: cover;
    background-attachment: fixed; 
    .header-image {
        position: absolute;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        opacity: 1;
        background-size: cover;
        background-attachment: fixed;
        transition: all 1s ease;
        &.hidden {
            opacity: 0;
        }
    }
    .title {
      color: #fff;
      z-index: 1000;
      font-family: "LampionW00-Regular";
      letter-spacing: 1rem;
    }
  }

}
.set-index(@index) {
  z-index: @index;
}
.index-0 {
  .set-index(100);
}
.index-1 {
  .set-index(90);
}
.index-2 {
  .set-index(80);
}
.index-3 {
  .set-index(70);
}

              
            
!

JS

              
                const data: any[]= [
  {
    title: 'haru',
    section: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
    album: 4
  },
  {
    title: 'natsu',
    section: 'Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. ',
    album: 3
  },
  {
    title: 'aki',
    section: 'At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. ',
    album: 6
  },
  {
    title: 'yuki',
    section: 'Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat...',
    album: 1
  }
]

class ImageContainer extends React.Component<any, any> {
    constructor(props: any, context: any) {
        super(props, context);
        this.state = {
            imageOnload: false
        }
    }
    render() {
        const src = this.props.src;

        return(
            <div className="album-item">
                <div className="image-wrapper">
                    {this.state.imageOnload && <img className="image large" src={src.origin}/>}
                    <img 
                        className={this.state.imageOnload ? "image placeholder hidden" : "image placeholder"}
                        onLoad={this.imageOnload.bind(this, src.origin)}
                        src={src.placeholder}/>
                </div>
            </div>

        )
    }
    private imageOnload(src: any) {
        let image = new Image();
        image.src = src;
        image.onload = () => {
            this.state.imageOnload = true;
            this.setState(this.state);
        }
    }

}


class Album extends React.Component<any, any>{
    private srcList: any = [];
    componentWillMount(){
        let index = this.props.index;
        for(let i = 0; i < this.props.album; i++) {
          let src = {};
          src.origin =  `https://unsplash.it/400/400/?image=${i}${index}`;
          src.placeholder =  `https://unsplash.it/8/8/?image=${i}${index}`;
          this.srcList.push(src);
      }
    }

  render() {
    return(
      <div className="album">
        {
            this.srcList.map((item: any, index: number) => <ImageContainer key={index} src={item}/>
        )}
      </div>
    )  
  }

  
}


class Container extends React.Component<any, any> {
  render() {
    const item: any = this.props.item;
    return (
        <div className="inner-container">
            <div className="sliding-block">
                <Album album={item.album} index={this.props.index}/>
            </div>
            <div className={this.props.pausing ? "static-block pausing" : "static-block"}>
                <div className="section">
                    <h2 className="title">
                    {item.title}
                    </h2>
                    <p>{item.section}</p>
                </div>
            </div>
        </div>
    )
  }
}

class Slider extends React.Component<any, any> {
    private containers: any[] = [];
    private posMap: any[] = [];

    constructor(props: any, context: any) {
        super(props, context);
        this.state = {
            currentIndex: undefined,
            pauseIndex: undefined,
            imageOnload: false
        }
    }

    componentDidMount() {
       this.setPosMap();
        window.addEventListener('resize', this.setPosMap.bind(this));
        window.addEventListener('scroll', this.onScroll.bind(this));
    }

    componentWillUnmount() {
        window.removeEventListener('scroll', this.onScroll.bind(this))
    }

  render() {
    const data: any[] = this.props.data;
    const imageSrc: any = {
        large: 'https://unsplash.it/1200/700/?image=252',
        placeholder: 'https://unsplash.it/24/14/?image=252'
    }
    return (
      <div className="slider">
        <div className="header container" style={this.state.imageOnload ? {backgroundImage: `url(${imageSrc.large})`} : {}}>
            <img 
                className={this.state.imageOnload ? "header-image placeholder hidden" : "header-image placeholder"}
                onLoad={this.imageOnload.bind(this, imageSrc.large)}
                src={imageSrc.placeholder}/>
            <h1 className="title">Page Slider</h1>
        </div>
        {data.map((item: any, index: number) => (
            <div className={index == this.state.currentIndex ? `container index-${index} current`
                                                    : `container index-${index}`}
                ref={(component: any) => this.containers[index] = component}>
                <Container 
                    item={item} 
                    key={index} 
                    index={index}
                    pausing={index == this.state.pauseIndex}/>
            </div>
        ))}
      </div>
    )
  }

  private imageOnload(src: any) {
      let image = new Image();
      image.src = src;
      image.onload = () => {
        this.state.imageOnload = true;
        this.setState(this.state)
      }
  }

  private setPosMap() {
     this.containers.map((item: HTMLElement, index: number) => {
       this.posMap[index] = {
         from: item.offsetTop,
         to: item.offsetTop + item.scrollHeight
       }
     })
  }

  private onScroll() {
    const windowScrollY: any = window.scrollY;
    const pausingRange: any = window.scrollY + window.innerHeight; 

    this.posMap.map((item: any, index: number) => {
        if(windowScrollY < this.posMap[0].from) {
            this.state.currentIndex = 0;
        }else if(windowScrollY > item.from && windowScrollY < item.to) {
            this.state.currentIndex = index + 1;
        }

        if(pausingRange > item.from && pausingRange < item.to) {
            this.state.pauseIndex = index;
        }
        
    })
    this.setState(this.state);
  }

}

ReactDOM.render(<Slider data={data} />,document.getElementById('root'));
              
            
!
999px

Console