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

              
                <meta name="viewport" content="width=device-width,initial-scale=1">

<div class="switches">
    
    <!-- WORM -->
    
    <div class="ground_block">
        <div class="ground_block_wrap">
            <h3>Worm</h3>
            <div class="ground_block_wrap_switch">
                <svg id="worm"	 viewBox="0 0 63 47.8">
                    <path id="worm-on" d="M47.9,37.9c-9.3,0-10.5,0-16.8,0c-6.7,0-7,0-16.6,0c-19.5,0-19.3-28,0-28c7.7,0,11.4,0,17.7,0c5.8,0,7.8,0,15.7,0
	C68,9.9,68,37.9,47.9,37.9z"/>
                    <path id="worm-off" d="M47.9,37.9c-9.3,0-7.5-6-13.8-6c-6.7,0-3,6-12.6,6c-19.5,0-19.3-28,0-28c7.7,0,7.4-6,13.7-6c5.8,0,4.8,6,12.7,6
	C68,9.9,68,37.9,47.9,37.9z"/>
                </svg>
            </div>
        </div>
    </div>
    
    <!-- LEAF -->
    
    <div class="leaf_block">
        <div class="leaf_block_wrap">
            <h3>Leaf</h3>
            <div class="leaf_block_wrap_switch">
                <svg id="leaf"	 viewBox="-3 -4 146 160">
                    <path id="leaf-path" fill="none" stroke-width="32" stroke-linecap="round" stroke-miterlimit="10" d="M14,73.7c0,0,37.6,0,55.2,0
	s29.2-13.6,29.2-29.9C98.4,27.4,85,14,68.5,14S38.6,27.4,38.6,43.9c0,16.4,13.1,29.9,29.7,29.9s54.6,0,54.6,0"/>
                </svg>
            </div>
        </div>
    </div>
    
    <!-- BASKET -->
    
    <div class="basket_block">
        <div class="basket_block_wrap">
            <h3>Basket css</h3>
                <div class="basket_block_wrap_switch_body">
                    <div class="basket_block_wrap_switch_trigger"></div>
                    <div class="basket_block_wrap_switch"></div>
                </div>
        </div>
    </div>
    
    <!-- LIQUID -->
    
    <div class="egg_block">
        <div class="egg_block_wrap">
            <h3>Egg</h3>
            <div class="egg_block_wrap_switch">
                <svg id="egg"	 viewBox="0 0.5 112 37">
                    <path id="egg-st1"d="M52.6,32.5c-8.2,0-27.1,0-33.3,0c-19.5,0-19.3-28,0-28c7.7,0,25.5,0,33.3,0C72.8,4.5,72.8,32.5,52.6,32.5z"/>
                    <path id="egg-st2" d="M52.6,32.5c-8.2,0-27.1,0-33.3,0c-19.5,0-19.3-28,0-28c7.7,0,32.8,9.7,40.3,12.7C80.9,25.6,72.8,32.5,52.6,32.5z"/>
                    <path id="egg-st3" d="M86.7,32.5c-8.2,0-58,0-64.3,0c-19.5,0-22.8-19.1-2.8-19.6c12.2-0.3,26.3,7.3,38.6,9.3c9,1.4,17.9,1.6,28.9,0.5C102.9,21.2,106.9,32.5,86.7,32.5z"/>
                    <path id="egg-st4" d="M34.6,32.5c8.2,0,48.4,0,54.7,0c19.5,0,22.3-25.6,2.2-25.6c-11.1,0-9.8,12.8-26.9,14.8c-9,1-24.6,2.1-35.6,1C13.2,21.2,14.4,32.5,34.6,32.5z"/>
                    <path id="egg-st5" d="M59.3,32.5c12.8,0,27.1,0,33.3,0c19.5,0,19.3-28,0-28c-2.6,0-22.3,0-26.8,0c-4.5,0-5.7,6.5-1,9.4c5.7,3.6,9.5,1.6,10.3,6.5s-14.7,4.3-18.6,4.5C45.8,25.4,46.5,32.5,59.3,32.5z"/>
                    <path id="egg-st6" d="M91.9,32.5c-8.2,0-27.1,0-33.3,0c-19.5,0-19.3-28,0-28c7.7,0,25.5,0,33.3,0C112.1,4.5,112.1,32.5,91.9,32.5z"/>
                </svg>
            </div>
        </div>
    </div>
    
    
    <!-- SCALE -->
    
    <div class="scale_block">
        <div class="scale_block_wrap">
            <h3>Flashy scale</h3>
            <div class="scale_block_wrap_switch">
                <div class="scale_block_wrap_trigger_off"></div>
                <div class="scale_block_wrap_trigger"></div>
            </div>
        </div>
    </div>
    
	<!---->
	
</div>


<div class="wrap">
    <h1>SVG Switch</br>controls</br>animation with GSAP</h1>
</div>

              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Roboto:400,500,700);

// mixins

@mixin centerer-top {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, 6%) ;
}

@mixin centerer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 50%) ;
}

@mixin width-size {
    padding:40px;
    width:70%;
    max-width:800px;
    margin:0 auto;
}

// colors

$body: #37a28a;

$ground: #865b32;
$worm: #fffd67;

$leaf-ground: #79c952;
$leaf-switch: #383886;
$leaf: #fffc23;

$basket-ground: #788b92;
$basket: #2e3c51;
$ball: #fdb405;

$egg-ground: #e9e2b2;
$yolk: #fdc005;

$scale-ground: #92cfce;
$scale: #fffc00;
$scale-switch: #229cb2;



// global styles

body{
    font-family: 'Roboto', sans-serif;
    background: $body;
}

h1{
    color:white;
}

h3{
    padding:20px;
    color: black;
    opacity:0.4;
}

.wrap{
    @include centerer-top;
    @include width-size;
    z-index:-1;
    height:450px;
    margin:0 auto;
    border: 3px solid white;
}

.switches{
    margin-top:300px;
}

// uniqe styles
// worm

.ground{
    &_block{
        position:relative;
        width:100%;
        height:300px;
        background: $ground;
        &_wrap{
            @include width-size;
            &_switch{
                cursor:pointer;
                @include centerer;
                top:43%;
                width:111px;
                height:36px;
                border-radius:100px;
                background: darken($ground,20%);
                transition:all 0.3s;
            }
        }
    }
}

#worm{
    margin:-6px 4px 0;
    height: 48px;
    fill: $worm;
    &-on{
        
    }
    &-off{
        display:none;
    }
}

//leaf

.leaf{
    &_block{
        position:relative;
        width:100%;
        height:300px;
        background: $leaf-ground;
        &_wrap{
            @include width-size;
            &_switch{
                cursor:pointer;
                @include centerer;
                top:43%;
                width:111px;
                height:35px;
                border-radius:100px;
                background: $leaf-switch;
                transition:all 0.3s;
            }
        }
    }
}

#leaf{
    margin:-36px 6px 0;
    width: 100px;
    stroke: $leaf;
}

//basket

.basket{
    &_block{
        position:relative;
        width:100%;
        height:300px;
        background: $basket-ground;
        &_wrap{
            @include width-size;
            &_switch{
                position:absolute;
                top:0;
                left:0;
                border-radius:100px;
                width:111px;
                height:36px;
                background: $basket;
                transition:all 0.3s cubic-bezier(0.600, 0.040, 0.375, 1.305);
                &_trigger{
                    position:absolute;
                    z-index:9999;
                    bottom: 0px;
                    top:0;
                    left:0;
                    margin:4px;
                    width:62px;
                    height:28px;
                    border-radius:100px;
                    background: $ball;
                    transition:all 0.3s cubic-bezier(0.600, 0.040, 0.375, 1.305);
                }
                &_body{
                    cursor:pointer;
                    @include centerer;
                    top:43%;
                    width:111px;
                    height:36px;
                }
            }
        }
    }
}

.basket_trigger-anim{
    animation: bounce 1.4s forwards;
}
.basket-anim{
    animation: resize 1.2s forwards;
}

@keyframes bounce {
    18%,20% {
        left:0;
        width: 28px;
        top:0px;
        animation-timing-function: cubic-bezier(0.105, 0.810, 0.160, 0.980);
    }
    40% {
        top:-60px;
        left: 20px;
        width: 28px;
       
    }
    45% {
        top:0px;
        left: 30px;
        width: 28px;
        
    }
    55% {
        top:-20px;
        left: 40px;
        width: 28px;
        animation-timing-function: cubic-bezier(1.000, 0.000, 0.000, 1.000);
    }
    60% {
        top:0px;
        left: 50px;
        width: 28px;
        
    }
    70% {
        top:-10px;
        left: 60px;
        width: 38px;
        animation-timing-function: cubic-bezier(0.105, 0.810, 0.160, 0.980);
    }
    80% {
        top:0px;
        left: 41px;
        width: 62px;
        
    }
    100% {
        top:0px;
        left: 41px;
        width: 62px;
        
    }
}

@keyframes resize {
    10% {
        left:0;
        width: 28px;
        animation-timing-function: cubic-bezier(0.105, 0.810, 0.160, 0.980);
    }
    20% {
        left: 0px;
        width: 28px;
        background: $basket;
       
    }
    70% {
        left: 40px;
        width: 80px;
        animation-timing-function: cubic-bezier(0.105, 0.810, 0.160, 0.980);
    }
    100% {
        left:0px;
        width: 111px;
        background: #f34f4f;
    }
}

// egg

.egg{
    &_block{
        position:relative;
        width:100%;
        height:300px;
        background: $egg-ground;
        &_wrap{
            @include width-size;
            &_switch{
                cursor:pointer;
                @include centerer;
                top:43%;
                width:111px;
                height:36px;
                border-radius:100px;
                background: white;
                transition:all 0.3s;
            }
        }
    }
}

#egg{
    width:111px;
    fill: $yolk;
    &-st2, &-st3, &-st4, &-st5, &-st6{
        display:none;
    }
}

//basket

.scale{
    &_block{
        position:relative;
        width:100%;
        height:300px;
        background: $scale-ground;
        &_wrap{
            @include width-size;
            &_switch{
                overflow:hidden;
                cursor:pointer;
                @include centerer;
                top:43%;
                width:111px;
                height:36px;
                border-radius:100px;
                transition:all 0.3s;
            }
            &_trigger{
                position:absolute;
                z-index:9999;
                bottom: 0px;
                top:0;
                left:0;
                margin:4px;
                width:40px;
                height:28px;
                border-radius:100px;
                background: $scale;
                &_off{
                    position:absolute;
                    z-index:9999;
                    bottom: 0px;
                    top:0;
                    right:0;
                    margin:4px;
                    width:40px;
                    height:28px;
                    border-radius:100px;
                    background: $scale-switch;
                    transform: scale(5);
                }
            }
        }
    }
}
              
            
!

JS

              
                // cleaning console

console.clear();

// vars

var wormTl = new TimelineLite({paused:true}),
    worm = $('.ground_block_wrap_switch'),
    //--//
    leafTl = new TimelineLite({paused:true}),
    leaf = $('.leaf_block_wrap_switch'),
    //--//
    basket = $('.basket_block_wrap_switch_body'),
    //--//
    eggTl = new TimelineLite({paused:true}),
    egg = $('.egg_block_wrap_switch'),
    //--//
    scaleTl = new TimelineLite({paused:true}),
    scaleBackTl = new TimelineLite({paused:true}),
    scale = $('.scale_block_wrap_switch');


//--- WORM timeline ---//
 
wormTl.to('#worm-on', .2, {morphSVG: '#worm-off'})
      .to('#worm-on', .2, {morphSVG: '#worm-on'})
      .to('#worm', .3, {x:20, y:-1}, '-=0.3')
      .to('#worm-on', .2, {morphSVG: '#worm-off'})
      .to('#worm-on', .3, {morphSVG: '#worm-on'})
      .to('.ground_block_wrap_switch', .3, {background:"#f34f4f"},'-=0.3')
      .to('#worm', .3, {x:40}, '-=0.4');

// controls

worm.click(function(){
    if (wormTl.progress() == 0){
      wormTl.play();
    } else{
        wormTl.reverse();
    }
});


//--- WORM timeline ---//

leafTl.fromTo("#leaf-path", 0.3, {drawSVG:'0% 14%'},{drawSVG:'0% 50%',ease: Power4.easeIn})
    .to("#leaf-path", 0.4, {drawSVG:"86% 100%",ease: Power2.easeOut})
    .to('.leaf_block_wrap_switch', .3, {background:"#f34f4f"},'-=0.3');

// controls

leaf.click(function(){
    if (leafTl.progress() == 0){
      leafTl.play();
    } else{
        leafTl.reverse();
    }
});


//--- BASKET timeline ---//
// controls

basket.click(function(){
    if ( $('.basket_block_wrap_switch_trigger').hasClass('basket_trigger-anim')){
      $('.basket_block_wrap_switch_trigger').animate({"left":"0px"}).removeClass('basket_trigger-anim');
      $('.basket_block_wrap_switch').removeClass('basket-anim');
    }else{
      $('.basket_block_wrap_switch_trigger').toggleClass('basket_trigger-anim');
      $('.basket_block_wrap_switch').toggleClass('basket-anim');
    }
});


//--- EGG timeline ---//

eggTl.to('#egg-st1', .1, {morphSVG: '#egg-st2', ease: Power1.easeOut})
     .to('#egg-st1', .05, {morphSVG: '#egg-st3', ease: Expo.easeIn})
.to('#egg-st1', .05, {morphSVG: '#egg-st4', ease: Power4.easeOut})
.to('#egg-st1', .1, {morphSVG: '#egg-st5', ease: Power2.easeOut})
.to('#egg-st1', .15, {morphSVG: '#egg-st6', ease: Power2.easeOut})
.to('.egg_block_wrap_switch', .3, {background:"#f34f4f"},'-=0.2');

// controls

egg.click(function(){
    if (eggTl.progress() == 0){
      eggTl.play();
    } else{
        eggTl.reverse();
    }
});


//--- SCALE timeline ---//

scaleTl.to('.scale_block_wrap_trigger', .3, {scale:5, backgroundColor:"#f34f4f", ease:Power4.easeOut})
       .to('.scale_block_wrap_trigger_off', .2, {scale:1, backgroundColor:"#f34f4f", zIndex:"99999", ease:Power4.easeOut}, "-=0.2")
       .to('.scale_block_wrap_trigger_off', .3, {scale:5, backgroundColor:"#fffc00", ease:Power4.easeOut})
       .to('.scale_block_wrap_trigger_off', .2, {scale:1, ease:Power4.easeOut}, "-=0.2");

// controls

scale.click(function(){
    if (scaleTl.progress() == 0){
      scaleTl.play();
    } else{
      scaleTl.reverse();
    }
});

              
            
!
999px

Console