我已經附加了html中三個對象的代碼。請看看在SO碼操場或在這裏:http://jsfiddle.net/kr34643L/div可以旋轉,span不能旋轉,但它可以動畫轉換
第一個(ID1)是DIV,我可以通過CSS3旋轉。
第二個(id2)是範圍並且不可能以相同的方式旋轉它。
但是可以在轉換時旋轉範圍(id3)。只有它不會停留在那個位置上。
我已經看到了有關設置顯示器塊或inline-block的的答案,但我真的不明白,爲什麼我要改變的顯示樣式。特別是當轉型運作良好,但只能保持最終狀態時。
var id1 = document.getElementById('id1');
var id2 = document.getElementById('id2');
var id3 = document.getElementById('id3');
var rotate1 = 0;
var rotate2 = 0;
var rotate3 = 0;
id1.addEventListener("click", function(){
rotate1 = rotate1 ? 0 : 45;
id1.style.transform = "rotate("+rotate1+"deg)";
});
id2.addEventListener("click", function(){
rotate2 = rotate2 ? 0 : 45;
id2.style.transform = "rotate(" + rotate2 + "deg)";
});
id3.addEventListener("click", function(){
rotate3 = rotate3 ? 0 : 45;
id3.style.transform = "rotate(" + rotate3 + "deg)";
id3.style.transition = "transform 2s";
});
#id1, #id2, #id3 {
width: 100px;
height: 15px;
border: 2px solid;
}
<div class="centerbox">
<div id="id1" style="cursor:pointer">div can rotate</div>
<span id="id2" style="cursor:pointer">span doesn't</span><br>
<span id="id3" style="cursor:pointer">span can transform though</span>
</div>
UPDATE
- 上面的說明僅適用於Chrome的
- 上火狐 ID2和ID3不旋轉以及轉換id3不起作用
- 上IE11所有旋轉和ID3的過渡工作
當我申請時,我有你的'id2'' span''點擊旋轉:'position:absolute' not working,但是,對於第二個範圍。另外我在最後一個元素 – s0rfi949
@ s0rfi949上看不到FF上的任何轉換。感謝關於FF的提示。我描述的問題發生在Chromium上。我也會檢查IE11。所以它更加複雜... – NilsB