2016-06-27 7 views
2

divを回転させるコードがあり、どの方向に向いているのか把握したいと思います。
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

だから、もう一度何を意味するのですか? –

+0

CSS「方向」を意味しますか? – Mohammad

+0

OPがX、Y方向(上、下、左、右)を要求しました – Akam

答えて

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; 
} 
関連する問題