Ada*_*dam 19 javascript css sass css3
我想为sass创建一个mixin,它将旋转应用于指定的元素.mixin应该采用一个参数,表示要应用的旋转度数.
从css3please.com,我发现了一种跨浏览器的方式来实现CSS:
.box_rotate {
-moz-transform: rotate(7.5deg); /* FF3.5+ */
-o-transform: rotate(7.5deg); /* Opera 10.5 */
-webkit-transform: rotate(7.5deg); /* Saf3.1+, Chrome */
-ms-transform: rotate(7.5deg); /* IE9 */
transform: rotate(7.5deg);
filter: progid:DXImageTransform.Microsoft.Matrix(/* IE6–IE9 */
M11=0.9914448613738104, M12=-0.13052619222005157,M21=0.13052619222005157, M22=0.9914448613738104, sizingMethod='auto expand');
zoom: 1;
}
Run Code Online (Sandbox Code Playgroud)
除了讨厌的IE矩阵表示法之外,这对于混音来说都非常容易.有没有人对使用sass,javascript或两者的组合将度数转换为IE矩阵转换的方法有任何建议?
meo*_*meo 21
你去:
上海社会科学院:
@mixin rotate( $degrees )
-webkit-transform: rotate(#{$degrees}deg)
-moz-transform: rotate(#{$degrees}deg)
-ms-transform: rotate(#{$degrees}deg)
-o-transform: rotate(#{$degrees}deg)
transform: rotate(#{$degrees}deg)
filter: progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=#{cos($degrees)}, M12=-#{sin($degrees)}, M21=#{sin($degrees)}, M22=#{cos($degrees)})
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=#{cos($degrees)}, M12=-#{sin($degrees)}, M21=#{sin($degrees)}, M22=#{cos($degrees)})"
zoom: 1
Run Code Online (Sandbox Code Playgroud)
SCSS:
@mixin rotate( $degrees ) {
-webkit-transform: rotate(#{$degrees}deg);
-moz-transform: rotate(#{$degrees}deg);
-ms-transform: rotate(#{$degrees}deg);
-o-transform: rotate(#{$degrees}deg);
transform: rotate(#{$degrees}deg);
filter: progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=#{cos($degrees)}, M12=-#{sin($degrees)}, M21=#{sin($degrees)}, M22=#{cos($degrees)});
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=#{cos($degrees)}, M12=-#{sin($degrees)}, M21=#{sin($degrees)}, M22=#{cos($degrees)})";
zoom: 1;
}
Run Code Online (Sandbox Code Playgroud)
用法:
@include rotate( 24 )
Run Code Online (Sandbox Code Playgroud)
或者你可以简单地使用罗盘,让你的生活更轻松:P
ada*_*mse 10
的旋转矩阵被定义为
[[cos(A), -sin(A)],
[sin(A), cos(A)]]
Run Code Online (Sandbox Code Playgroud)
A角度在哪里.M11在IE矩阵中是第一行的第一个元素; M12:第一行的第二个元素等
JavaScripts Math.sin并Math.cos使用弧度操作,因此您必须将度数转换为弧度
radians = degrees * Math.PI / 180
Run Code Online (Sandbox Code Playgroud)
把这个放在一起我们得到这个功能:
function rotationMatrix(degrees) {
var A = degrees * Math.PI / 180;
return [[Math.cos(A), -Math.sin(A)], [Math.sin(A), Math.cos(A)]]
}
Run Code Online (Sandbox Code Playgroud)
例:
rotationMatrix(10)
// => [[0.984807753012208, -0.17364817766693033],
// [0.17364817766693033, 0.984807753012208]]
Run Code Online (Sandbox Code Playgroud)
此函数允许将度数转换为IE矩阵变换.
//deg input defines the requested angle of rotation.
function degreeToIEMatrix(deg){
var deg2radians = Math.PI * 2 / 360;
var rad = deg * deg2radians ;
var costheta = Math.cos(rad);
var sintheta = Math.sin(rad);
var M11 = costheta;
var M12 = -sintheta;
var M21 = sintheta;
var M22 = costheta;
}
Run Code Online (Sandbox Code Playgroud)
你会在这里找到更多的信息.
| 归档时间: |
|
| 查看次数: |
10493 次 |
| 最近记录: |