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.

            
              <html>
<head>
  <title>swingdrag</title>
  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
  
</head>
<body>
  <div id="container">
    <span class="fa fa-hand-o-up"></span>
    Just drag me!
	</div>
  
	<div id="shadowContainer">
    <span class="fa fa-hand-o-up"></span>
    Drag me with shadow and high speed influence!
	</div>
  
  <script>
    window.addEventListener('load', function () {

      $("#container").swingdrag({
        maxRotationAngleDeg: 20,
        showShadow: false,
        pickUpScaleFactor: 1.1,
        speedInfluenceFactor: 2.5
      });
      
      $("#shadowContainer").swingdrag({
        maxRotationAngleDeg: 35,
        showShadow: true,
        pickUpScaleFactor: 1.1,
        speedInfluenceFactor: 4.0
      });
      
		}, false);
  </script>
  
</body>
</html>
            
          
!
            
              #shadowContainer {
  cursor: pointer;
  width: 300px;
  height: 200px;
  background-color: #0b1423;
  font-size: 2em;
  font-family: 'Arial';
  color: #DADADA;
  text-align: center;
  margin: auto;
}

#container {
  cursor: pointer;
  width: 300px;
  height: 200px;
  background-color: #ab1423;
  font-size: 2em;
  font-family: 'Arial';
  color: #DADADA;
  text-align: center;
  margin: auto;
}

.swingdrag {
  transition: transform 1s cubic-bezier(0.165, 0.84, 0.44, 1), box-shadow 0.3s cubic-bezier(0.165, 0.84, 0.44, 1); }
  .swingdrag.shadow {
    box-shadow: 0 12px 11px #383838; }
  .swingdrag.dragging {
    z-index: 1000; }

            
          
!
            
              !function(t){function e(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),(new(n(1).SwingDragPlugIn)).register()},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=n(2),i=n(3),a=n(4),s=function(){function t(t){this.plugInName="ui.swingdrag",this.swingDragOptions=t,this.swingDragOptions||(this.swingDragOptions=new o.SwingDragOptions),this.updateCurrentDragVectorIntervalMS=1e3/30}return t.prototype.destroy=function(){if($&&$.Widget&&($.Widget.prototype.destroy.call(this),this.element)){var t=$(this.element);t.draggable("destroy"),this.disableSwing(t),this.disableSwingDragShadow(t),t.removeClass("dragging"),$(this.element).css({transform:""})}},t.prototype.register=function(){$.widget(this.plugInName,this)},t.prototype.enableSwing=function(t){t.addClass("swingdrag")},t.prototype.disableSwing=function(t){t.removeClass("swingdrag")},t.prototype.enableSwingDragShadow=function(t){t.addClass("shadow")},t.prototype.disableSwingDragShadow=function(t){t.removeClass("shadow")},t.prototype.updateElementTransform=function(t,e,n){t.css({transform:"rotate("+e+"deg) scale("+n+")"})},t.prototype._create=function(){var t=this,e=$(this.element);this.initOptions(),this.enableSwing(e);var n,o,s=new i.Vector2D,r=new i.Vector2D,g=new i.Vector2D,p=function(){var n=e.position();s.x=n.left,s.y=n.top,g.x=s.x-r.x,g.y=s.y-r.y;var i=Math.abs(g.x)/t.updateCurrentDragVectorIntervalMS;i*=t.swingDragOptions.speedInfluenceFactor,o=a.MathUtils.mapInterval(i,0,5,0,t.swingDragOptions.maxRotationAngleDeg),o*=g.x>0?1:-1,t.updateElementTransform(e,o,t.swingDragOptions.pickUpScaleFactor),r.x=s.x,r.y=s.y};e.on("dragstart",function(i){e.addClass("dragging"),t.swingDragOptions.showShadow&&t.enableSwingDragShadow(e),s.x=e.position().left,s.y=e.position().top,o=Math.abs(t.swingDragOptions.maxRotationAngleDeg),n=setInterval(p,t.updateCurrentDragVectorIntervalMS)}),e.on("dragstop",function(o){e.removeClass("dragging"),n&&clearInterval(n),t.disableSwingDragShadow(e),t.updateElementTransform(e,0,1)}),e.data("draggable")||e.draggable()},t.prototype.initOptions=function(){this.swingDragOptions=new o.SwingDragOptions,(this.options.rotationAngleDeg||0===this.options.rotationAngleDeg)&&(this.swingDragOptions.maxRotationAngleDeg=this.options.rotationAngleDeg),(this.options.maxRotationAngleDeg||0===this.options.maxRotationAngleDeg)&&(this.swingDragOptions.maxRotationAngleDeg=this.options.maxRotationAngleDeg),void 0!==this.options.showShadow&&(this.swingDragOptions.showShadow=this.options.showShadow),(this.options.pickUpScaleFactor||0===this.options.pickUpScaleFactor)&&(this.swingDragOptions.pickUpScaleFactor=this.options.pickUpScaleFactor),(this.options.speedInfluenceFactor||0===this.options.speedInfluenceFactor)&&(this.swingDragOptions.speedInfluenceFactor=this.options.speedInfluenceFactor)},t.prototype._setOption=function(t,e){switch($.Widget.prototype._setOption.apply(this,arguments),t){case"rotationAngleDeg":case"maxRotationAngleDeg":this.swingDragOptions.maxRotationAngleDeg=e;break;case"showShadow":this.swingDragOptions.showShadow=e;break;case"pickUpScaleFactor":this.swingDragOptions.pickUpScaleFactor=e;break;case"speedInfluenceFactor":this.swingDragOptions.speedInfluenceFactor=e}},t}();e.SwingDragPlugIn=s},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){this.maxRotationAngleDeg=20,this.showShadow=!0,this.pickUpScaleFactor=1.1,this.speedInfluenceFactor=2}return t}();e.SwingDragOptions=n},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){this.x=0,this.y=0}return t}();e.Vector2D=n},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.mapInterval=function(e,n,o,i,a){return i+(a-i)/(o-n)*(t.clamp(e,n,o)-n)},t.clamp=function(t,e,n){return Math.min(Math.max(t,e),n)},t}();e.MathUtils=n}]);
            
          
!
999px
Loading ..................

Console