0

I'm trying to figure out how to enable visitors to drag to rotate a 3D div using .draggable(). Currently the div rotates but also moves vertically and horizontally making the process touchy and unpredictable. I would like the origin of the div to stay fixed, and the "dragging" to only affect the rotation, so users can "spin" the div around to see the other sides.

here is link to the codepen: http://codepen.io/armandhammer8/pen/IiBga

$('.anime').draggable({ drag: function(event, ui){

var rotateCSS = 'rotate(' + ui.position.left + 'deg)'; $(this).css({ 'transform': rotateCSS, '-moz-transform': rotateCSS, '-webkit-transform': rotateCSS }); 

Thanks in advance!

The div element is a little house:

I want to be able to spin it around

1 Answer 1

2

The built in functionality of draggable is giving you the problems.

It's not so hard to get the functionality by yourself and stop using draggable.

Javascript:

var offset = 0, startX; var elem = document.getElementById("element"); $('.draggable').on('mousedown', function (e) { startX = e.pageX - offset; }) .on('mouseup', function() { startX = null; }) .on('mousemove', function (e) { if(startX) { offset = e.pageX - startX; elem.style['-webkit-transform'] = 'rotateY(' + offset + 'deg)'; } }); 

demo

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.