2016-09-19 79 views

回答

0

旋轉似乎被綁定到撥號的rotation值。正/負角度意味着順時針/逆時針。

您需要將當前角度與上一個角度進行比較,以查看按鈕正在旋轉到的方向。

var previousRotation = 0; 
 

 
Draggable.create('#dial', { 
 
    type:'rotation', 
 
    throwProps: true, 
 
    onDrag: function() { 
 
    var yourDraggable = Draggable.get('#dial'); 
 
    
 
    var dir = (yourDraggable.rotation - previousRotation) > 0 ? "clockwise" : "counter-clockwise"; 
 
    console.log("Direction: " + dir + ", angle: " + yourDraggable.rotation); 
 
    
 
    previousRotation = yourDraggable.rotation; 
 
    } 
 
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenLite.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/utils/Draggable.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/plugins/CSSPlugin.min.js"></script> 
 

 
<img id="dial" src="http://greensock.com/wp-content/uploads/custom/draggable/img/knob.png" width="250" height="250">

+0

好極了!感謝您及時的回覆。 – Jetchy