I'm try to get a div to drag much like a boat through water, but I'm having some trouble getting the rotation right.
Here is what I have so far:
jsFiddle
JS
var start, stop;
$('#canoe').draggable({
containment: '#board',
cursor: 'none',
cursorAt: {
top: 5
},
drag: function (event, ui) {
start = ui.position.left;
setTimeout(function () {
stop = ui.position.left;
}, 150);
$('#canoe').css({
'transform': 'rotate(' + (start - stop) + 'deg)'
});
}
});
CSS
#board {
height:100%;
width:100%;
background:blue;
}
#canoe {
background: #fff;
border-radius:100% 100% 100% 100%;
height:60px;
width:10px;
position:absolute;
left:50%;
bottom:0;
transform-origin:top center;
transition: transform .2s;
}
HTML
<div id="board">
<div id="canoe">A</div>
</div>
Is there a better way to get the rotation set up so that the front of the boat is always leading, even with a 360deg rotation?
Additional Context: I'm working on a Basic Game
Bounty update: I need the "boat" to be able to be dragged in a circle in one continuous motion without flipping/switching the rotation direction.
setTimeout
- jsfiddle.net/unuCD/9 – Submaxillary