/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function sample() { vmax = latest.x + 0.25; vmin = latest.x - 0.25; vrange = 0.50; hmax = latest.y + 0.25; hmin = latest.y - 0.25; hrange = 0.50; } function move() { var hposition = 0; var vposition = 0; vposition = ( ( ( latest.x - vmin ) / vrange ) * BRICKS_SPACE ) + BRICKS_MAXIMUM; hposition = ( ( latest.y - hmin ) / hrange ) * LEGS_SPACE; // Keep in bounds if( vposition > BRICKS_MAXIMUM ) { vposition = BRICKS_MAXIMUM; } else if( vposition < BRICKS_MINIMUM ) { vposition = BRICKS_MINIMUM; } if( hposition < LEGS_MINIMUM ) { hposition = LEGS_MINIMUM; } else if( hposition > LEGS_MAXIMUM ) { hposition = LEGS_MAXIMUM; } $( '#background' ).css( 'top', vposition ); $( '#legs' ).css( 'left', hposition ); }
Comments
