cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              @import url('https://fonts.googleapis.com/css?family=Roboto');

* {
    box-sizing: border-box;
}
body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    padding: 0;
    height: 100vh;
    width: 100%;
}
#root {
    width: 100%;
    height: 100%;
}
.wrapper {
    min-width: 400px;
    position: relative;
    width: 100%;
    overflow: hidden;
    height: 100%;
    .separator {
        height: 100%;
        width: 3px;
        background: #FFC300;
        position: absolute;
        z-index: 10;
    }
}
.layer {
    position: absolute;
    width: 100%;
    overflow: hidden;
    height: 100%;
    &.top {
        background: grey;   
        h3 {
            color: #FFC300;
        }
        p {
            color: #fff;
        }
    }
    &.bottom {
        z-index: 2;
        background: #eee;   
        h3 {
            color: #C70039;
        }
        p {
            color: grey;
        }
    }
}

.content-wrap {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    padding: 30px;
    .content-text {
        text-align: center;
    }
    div {
        width: 100px;
        flex-grow: 1;
    }
    img {
        height: 400px;
    }
    .white-one {
        -webkit-filter: invert(100%);
    filter: invert(100%);
    }
}
            
          
!
            
              
class SplitSlider extends React.Component {
    constructor(props) {
        super(props);
        this.state = { x: 0};
    }
    
    componentDidMount() {
        window.addEventListener("resize", this.resetSeparatorPosition);
        this.resetSeparatorPosition();
    }
    
    componentWillUnmount() {
        window.removeEventListener("resize", this.resetSeparatorPosition);
    }
    
    onMouseMove = (e) => {
        this.setState({x: e.pageX});
    };

    resetSeparatorPosition = () => {
        let wrapperWidth;
        if (this.refWrapper) {
            wrapperWidth = this.refWrapper.getBoundingClientRect().width;
        }
        this.setState({x: wrapperWidth / 2});
    };

    getSeparatorStyles = () => {
        let wrapperHeight;
        if(this.refWrapper) {
          wrapperHeight = this.refWrapper.getBoundingClientRect().height;
        }
        const p1 = {
	        x: this.state.x,
	        y: wrapperHeight,
        };

        const p2 = {
             x: this.state.x + 50,
             y: 0
        };
        //calculate te angle of the yellow separator based on the bottom and top points
        const angleDeg = Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
        return {
            left: `${this.state.x + 25}px`,
            transform: `rotate(${90 + angleDeg}deg)`,
        }
    };

    getStyles() {
        if (!this.state.x) {
            //default styles
            return {
                clipPath: 'polygon(0 0, 57% 0, 50% 100%, 0 100%)', 
            }
            this.getSeparatorStyles();
        }
        return {
         clipPath: `polygon(0 0, ${this.state.x + 50}px 0, ${this.state.x}px 100%, 0 100%)`, 
        }
    };
    render() {
        return (
            <div 
                className="wrapper" 
                onMouseMove={this.onMouseMove} 
                onMouseLeave={this.resetSeparatorPosition}
                ref={(c) => {this.refWrapper = c;}}    
            >
                 <div className="separator" style={this.getSeparatorStyles()}/>
                <div className="layer bottom" style={this.getStyles()}>
                    <div className="content-wrap">
                        <div className="content-text">
                            <h3>Oneplus 5</h3>
                            <p>The best of Android refined. OxygenOS is streamlined with feedback from our users for a refreshing user experience</p>
                        </div>
                            <img src="https://staticshop.o2.co.uk/product/images/bau-33174-oneplus-5sku-header-master-midnight-black-090617.png?cb=9c83d00dbe40c948b1fb9ea7dfe74b84"/>
                        <div className="helper"/>
                    </div>
                </div>
                <div className="layer top">
                    <div className="content-wrap">                
                      <div className="helper"/>
                         <img src="https://staticshop.o2.co.uk/product/images/bau-33174-oneplus-5sku-header-master-midnight-black-090617.png?cb=9c83d00dbe40c948b1fb9ea7dfe74b84" className="white-one"/>
                        <div className="content-text">
                            <h3>Never settle</h3><p>Leap into a truly immersive flagship experience. Our Full Optic AMOLED 18:9 display complements the masterfully.</p>
                        </div>
                    </div>
                </div>
            </div>);
    }
};

ReactDOM.render(
<SplitSlider />,
    document.getElementById('root')
);
            
          
!
999px
Loading ..................

Console