我有旋转div的代码,我想知道它面向哪个方向。
我如何找到div面向的方向?
function getDirectionX(elem){
lcelement = document.getElementById(elem);
// find direction lcelement is facing here
// return x;
}
function getDirectionY(elem){
lcelement = document.getElementById(elem);
// find direction lcelement is facing here
// return y;
}
答案 0 :(得分:3)
这有帮助吗?
https://jsfiddle.net/m3130qo8/1/
代码:
function spinit(){
var woah = document.getElementById('woah');
var deg = Math.floor(Math.random() * 360) + 0;
woah.style.webkitTransform = 'rotate('+deg+'deg)';
woah.style.mozTransform = 'rotate('+deg+'deg)';
woah.style.msTransform = 'rotate('+deg+'deg)';
woah.style.oTransform = 'rotate('+deg+'deg)';
woah.style.transform = 'rotate('+deg+'deg)';
var current_rotation = /[0-9]+/.exec(woah.style.transform);
document.getElementById('woah').innerHTML=current_rotation;
}