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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <!-- References Dribbble / Twitter / Hicon Pack -->
<div class='cs-ref'>
  <a class="cs-dribbble" href="https://dribbble.com/shots/14282817-UI-Click-Drag-Button" target="_blank">
    <div id='svgDribbble'></div>
  </a>
  <a class="cs-twitter" target="_blank" href="https://twitter.com/CosWiSe">
    <div id='svgTwitter'></div>
  </a>
  <a class="cs-hicon" target="_new" href="https://hicon.cosm.ws">
    <div id='svgHicon'></div>
  </a>
</div>

<!-- UI -->
<div class='container'>

  <div class='el-wrap'>

    <!-- Slider -->
    <div class='slider'>
      <div class='slider-text'>
        <div class='text'>
          Confirm
        </div>
      </div>
      <div class='slider-trigger'>
        <div class='controller' id='controller'>
          <i load-hicon='chevron-right' class='icon icon-opa'></i>
        </div>

        <div class='endpoint-container'>
          <div class='endpoint' id='controllerDrop'></div>
        </div>
      </div>

    </div>


    <!-- Button -->
    <div class='button btn-clickable'>
      <p class='text text-c'>Checkout</p>
      <i load-hicon='check' class='icon icon-check'></i>
    </div>


  </div>

</div>
              
            
!

CSS

              
                /*** PRESET ***/
// IMPORT
@import url('https://fonts.googleapis.com/css?family=Muli:300,400,700,900');

// VARIABLES 
:root {
  --canvasBG: #f1f3f9;
  --textC: #333333; // Light Blue
  --col1: #ff8c69; // Salmon
  --col2: ff696c; // Coral
  --col3: #1462ff; // Blue
  --col4: #f0f1f5; // Light Grey
  --col5:  rgba(239, 244, 255,1);  // Light Blue
  --SVGc: rgba(146, 156, 208,.8);
  --shadowC: rgba(74,116,201,1);
  --shadowDef: 0 3px 20px -3px var(--shadowC);
  --shadowDefAlt: 0 6px 30px -10px var(--shadowC);
}

// PLACEHOLDERS
%no-selection {
  // No selection
  -webkit-user-select: none;  
  -moz-user-select: none;     
  -ms-user-select: none;      
  user-select: none;    
}

// DEFAULT
html {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--canvasBG);
  height: 100vh;
  font-family: 'Muli', Arial, sans-serif;
  color: var(--textC);
  @extend %no-selection;
}

// SVGs
#dribbble {
  position: fixed;
  display: block;
  right: 70px;
  bottom: 16px;
  svg {
    display: block;
    width: 76px;
    height: 24px;
    fill: var(--SVGc);
  }
}
#twitter {
  position: fixed;
  display: block;
  right: 25px;
  bottom: 11px;
  svg {
    width: 24px;
    height: 24px;
    fill: var(--SVGc);
  }
}

#hicon {
  position: fixed;
  display: block;
  left: 25px;
  bottom: -42px;
  svg {
    width: 78px;
    height: 78px;
    fill: var(--SVGc);
  }
}

/*** UI ***/

// VARIABLES
:root {
  // sizes
  --sz: 50px;
  --radius: .8em;

  // colours
  --c-text: #ffffff;
  --c-black: #000;

  // timing
  --time: 299ms;
}

// PLACEHOLDERS
%center {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
%container {
  width: calc(var(--sz)*4);
  height: var(--sz);
  border-radius: var(--radius);
}

.container {
  width: auto;
  height: auto;
  margin: auto;
  padding: 0;
}

.el-wrap {
  @extend %container;
  position: relative;
  box-shadow: var( --shadowDef);
}

.el-wrap-shield:after {
  @extend %container;
  content: "";
  background: transparent;
  border: 5px solid transparent;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
}

/* Button */
.button {
  @extend %center;
  @extend %container;
  position: absolute;
  background: var(--col3);
  border-color: var(--col3);
  border-width: 5px;
  border-style: solid;
  transition: background var(--time) ease, border-color var(--time) ease;
  z-index: 3;
}

.btn-clickable {
  cursor: pointer;
  &:hover {
    background: lighten(#1462ff, 4%);
    border-color: lighten(#1462ff, 4%);
    transition: background var(--time) ease, border-color var(--time) ease;
  }
}

/* Slider */
.slider {
  @extend %container;
  @extend %center;
  justify-content: flex-end;
  position: absolute;
  background: var(--col3);
  border: 5px solid var(--col3);
  opacity: 0;
  z-index: 0;
  transition: background var(--time) ease, border-color var(--time) ease, opacity var(--time) ease;
}

.sldr-opa {
  opacity: 1;
  transition: opacity calc(var(--time)/2) ease;
}

.sldr-pos {
  z-index: 5;
}

.sldr-drag {
  background: lighten(#1462ff, 4%);
  border-color: lighten(#1462ff, 4%);
  transition: background var(--time) ease, border-color var(--time) ease;
}

/* Inside Slider */
.slider-text {
  @extend %container;
  @extend %center;
  position: absolute;
  box-sizing: border-box;
}
.text-d {
  opacity: .3;
  transition: opacity var(--time) ease;
}

.controller {
  @extend %center;
  box-sizing: border-box;
  width: calc(var(--sz) - 2px);
  height: calc(var(--sz) - 2px);
  background: lighten(#1462ff, 20%);
  border: 2px solid lighten(#1462ff, 30%);
  border-radius: .55em;
  position: absolute;
  top: 1.5px;
  left: 0;
}
.endpoint-container {
  @extend %container;
  @extend %center;
  justify-content: flex-end;
  background: trasparent;
}
.endpoint {
  border: 3px solid transparent;
  height: var(--sz);
  width: var(--sz);
  border-radius: 7px;
  margin: 0;
  position: relative;
}

.icon {
  color: var(--c-text);
  margin-top: 0px;
  width: 28px;
  height: 28px;
  transition: opacity var(--time) ease;
}

.icon-opa {
  opacity: 0;
  transition: opacity var(--time) ease;

}

.button .icon {
  margin-left: 4px;
}

.icon-check {
  display: none;
}

/* Text */
.text {
  font-size: 1em;
  color: var(--c-text);
  transition: opacity var(--time) ease;
}
              
            
!

JS

              
                // ICONS CALLBACK
hicon.replace();

// SVGs
$('#svgDribbble').load('https://s3-us-west-2.amazonaws.com/s.cdpn.io/373860/references.html #dribbble');
$('#svgTwitter').load('https://s3-us-west-2.amazonaws.com/s.cdpn.io/373860/references.html #twitter');
$('#svgHicon').load('https://s3-us-west-2.amazonaws.com/s.cdpn.io/373860/references.html #hicon');


/*

  ICON SET FROM 
  http://hicon.cosm.ws/

  And then replace the icon name in load-hicon.
  <i load-hicon="heart"></i>

  */

// CODE HERE
$(document).ready(function() {
  initDrag();
});

// Button
$(".btn-clickable").click(function() {
  setTimeout(function() {
    $(".slider").addClass("sldr-opa");
  }, 199); 
  setTimeout(function() {
    $(".slider").addClass("sldr-pos");
  }, 299); 
  setTimeout(function() {
    $(".button").removeClass("btn-clickable");
    $(".text-c").text("Done");
    $(".icon").removeClass("icon-check");
    loadController();
  }, 359);  
  setTimeout(function() {
    $(".icon").removeClass("icon-opa");
  }, 499); 
});


// Slider
// Initial status
var controller = $(".controller");
TweenMax.set(controller, {scale: 0, opacity: 0});

var sliderContainer = $(".endpoint-container"),
    tl = new TimelineLite(),
    dropTargets = $(".endpoint"),
    totlaTarges = 1,
    totalHit = 0;


// After load status
function loadController() {
  TweenMax.staggerTo(controller, .2, {scale: 1,opacity: 1, ease: Back.easeOut, force3D: true}), initDrag;
};

function initDrag() {
  Draggable.create(controller, {
    bounds: sliderContainer,
    edgeResistance: 1,
    type:'x',
    onPress: function() {

      this.sartX = this.x;
      this.sartY = this.y;

      this.offsetTop = this.startY - $(this.target).position().top;
      this.offsetLeft = this.startX - $(this.target).position().left;

    },
    onDragStart: function(){ 
      $(".slider").toggleClass("sldr-drag");
      $(".slider-text").toggleClass("text-d");
    }, 
    onDragEnd: function() {
      var dragThing = this;
      var dragID = this.target.id + "Drop";

      $.each(dropTargets, function (idx, spot) {
        var spotID = spot.id;
        var pos = $(spot).position();
        var diffTop = dragThing.offsetTop + pos.top;
        var diffLeft = dragThing.offsetLeft + pos.left;


        if (spotID === dragID) {
          if(dragThing.hitTest(spot, "70%")) {
            TweenMax.to(dragThing.target, .1, {x: diffLeft, y: diffTop, marginTop: "4px", marginLeft: "3px"});
            TweenMax.staggerTo(controller, .5, {scale: 0,opacity: 0, delay: .5, ease: Back.easeOut, force3D: true}, SliderOff);
            // Post action 
            function SliderOff() {
              setTimeout(function() {
                $(".slider").removeClass("sldr-opa");
              }, 499); 
              setTimeout(function() {
                $(".slider").removeClass("sldr-pos");
              }, 799); 
              setTimeout(function() {
                $(".el-wrap").addClass("el-wrap-shield");
              }, 499);
            }
          } else {
            TweenMax.to(dragThing.target, .5, {x: dragThing.startX, y: dragThing.startY});
          }
        }
      });
      $(".slider").toggleClass("sldr-drag");
      $(".slider-text").toggleClass("text-d");
    }
  })
};
              
            
!
999px

Console