Popmotion 5.0 example: SVG properties

In this example below you will see how to do a Popmotion 5.0 example: SVG properties with some HTML / CSS and Javascript

Forked from Popmotion's Pen Popmotion 5.0 sandbox.

Thumbnail
This awesome code was written by naeemshaikh27, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright naeemshaikh27 ©
  • HTML
  • CSS
  • JavaScript
    <div class="test-area">
    <h1>Velocity-based 3D drag effect</h1>
    <div class="box"></div>
</div>

/*Downloaded from https://www.codeseek.co/naeemshaikh27/popmotion-50-example-svg-properties-dMbvWW */
    body {
    background: #e25875;
}

h1 {
    text-align: center;
    font-family: Helvetica, sans-serif;
    font-weight: 300;
    color: rgba(255,255,255,.5);
    padding-top: 50px;
}

.test-area {
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    position: absolute;
    -moz-perspective: 500;
    -webkit-perspective: 500;
    perspective: 500;
    transform-style: preserve-3d;
}

.box {
    position: absolute;
    width: 150px;
    height: 150px;
    border-radius: 4px;
    background: white;
    top: 50%;
    left: 50%;
    margin-left: -75px;
    margin-top: -75px;
    will-change: transform;
    transform: translate3d(0);
}


/*Downloaded from https://www.codeseek.co/naeemshaikh27/popmotion-50-example-svg-properties-dMbvWW */
    var SELECTOR = '.box';
var velocityRange = [-1000, 1000];
var maxRotate = 30;
var smoothing = 100;
var box = ui.select(SELECTOR, {
    values: {
        x: 0, y: 0,
        rotateY: {
            watch: function (actor) {
                return actor.values.x.velocity;
            },
            mapFrom: velocityRange,
            mapTo: [-maxRotate, maxRotate],
            smooth: smoothing
        },
        rotateX: {
            watch: function (actor) {
                return actor.values.y.velocity;
            },
            mapFrom: velocityRange,
            mapTo: [maxRotate, -maxRotate],
            smooth: smoothing
        }
    }
});

var track2D = new ui.Track({
    values: {
        x: {},
        y: {}
    }
});

var springBack = new ui.Simulate({
    simulate: 'spring',
    spring: 500,
    friction: 0.3,
    values: {
        x: 0,
        y: 0
    }
});

$('body').on('touchstart mousedown', SELECTOR, function (e) {
    e.preventDefault();
    
    box.start(track2D, e);
});
    
$('body').on('touchend mouseup', function () {
    box.start(springBack);
});

Comments