代碼如下:function rotatePlusLink() {
$(".linkDiv").each(function () {
var tr = window.getComputedStyle($(this)[0], null).getPropertyValue("transform");
if (tr == 'none') {
this.css('transform', 'scale(1) rotate(0deg)');
return;
}
var values = tr.split('(')[1].split(')')[0].split(',');
var a = values[0];
var b = values[1];
var c = values[2];
var d = values[3];
var scale = Math.sqrt(a * a + b * b);
var sin = b / scale;
var angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
this.style.transform = 'rotate(' + (angle + 5) + 'deg) scale(' + scale + ')';
});
}
function rotateReduLink() {
$(".linkDiv").each(function () {
var tr = window.getComputedStyle($(this)[0], null).getPropertyValue("transform");
if (tr == 'none') {
this.css('transform', 'scale(1) rotate(0deg)');
return;
}
var values = tr.split('(')[1].split(')')[0].split(',');
var a = values[0];
var b = values[1];
var c = values[2];
var d = values[3];
var scale = Math.sqrt(a * a + b * b);
var sin = b / scale;
var angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
this.style.transform = 'rotate(' + (angle - 5) + 'deg) scale(' + scale + ')';
});
}這兩個函數(shù)中的linkDiv的設置 怎么能封裝成一個函數(shù)調用啊? 這兩個函數(shù)只有一個地方不一樣 就是設置屬性的那里,一個加號,一個減號。
javascript的函數(shù)封裝
炎炎設計
2019-05-03 18:15:58