2017-10-14 65 views
2

嗨,我们使用jquery rotatble插件旋转一个divjQuery的旋转()在程度

$(function() { 
 

 
     $('.new-multiple').rotatable(); 
 
});
.new-multiple{ 
 
    display:inline-block; 
 
}
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
 
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
 
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 

 
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/godswearhats/[email protected]/jquery.ui.rotatable.css"> 
 
<script src="https://cdn.jsdelivr.net/gh/godswearhats/[email protected]/jquery.ui.rotatable.min.js"></script> 
 

 
<div class="new-multiple"> 
 

 
    <img src="https://www.gravatar.com/avatar/322f808cb7a7e06d38ca4c8a441332fd?s=48&d=identicon&r=PG&f=1"> 
 
    </div>

但问题是,它利用辐射的选择转动股利。但我们需要旋转div使用度。即0到360度。如何如果您查看在https://github.com/godswearhats/jquery-ui-rotatable的文档,我们可以做到这一点

我试图

.rotatable({ 
     options: { 
      degrees: true 
     } 
});  

,但是这是不工作

+0

看一看[这](https://www.w3schools.com/tags/ tryit.asp?filename = tryhtml5_canvas_rotate) – matt

+1

@matt不知道Canvas旋转是如何与jQuery UI插件和CSS相关的。 – Twisty

回答

0

,因为我需要获得学位的旋转我转换给定的弧度度停止事件

$('.new-multiple').rotatable({ 


     stop: function(e, ui){ 
      if(ui.angle.current<0){ 
        var given_angle=ui.angle.current+2*Math.PI; 
       } 
       else{ var given_angle=ui.angle.current; } 
       var new_angle=Math.round(given_angle*180/ Math.PI)+"deg"; 
       $(".new-multiple").css("transform","rotate("+new_angle+")"); 
     } 

    }); 
+0

'ui.angle.degree'为你提供学位。 – Twisty

+0

我会检查这个。这意味着$(“。new-multiple”)。css(“transform”,“rotate(”+ ui.angle.degree +“)”); ? –

1

您将看到:

degrees:以度首发阵容(默认为0)

因此,您无法使用您尝试的选项。它将需要是0到360之间的int值,而不是true

例如,如果你想在45度到初始化旋转,你可以使用:

$(function() { 
    $('.new-multiple').rotatable({ 
    degress: 45 
    }); 
}); 

希望有所帮助。

+0

你可以请检查这个https://stackoverflow.com/questions/48319486/image-orientation-changing-in-jquery-image-upload-and-preview-function –