我想讓圖像在懸停時旋轉180度。當圖像被點擊/選擇時,我希望圖像保持在該位置,直到它應該返回到其原始位置時再次被選擇。旋轉懸停,然後在點擊時保持該位置,再次單擊時返回到原始位置
我已經嘗試了CSS,它可以用於懸停,但不會持續。然後我發現了一些使用jQuery的帖子,但是在我選擇的例子中,我發現它非常基本,但是沒有足夠的理解它使圖像返回。
的HTML
<div class="conversionFormE" id="switch1">
<label class="swapHide">Swap?</label>
<input type="button" class="rotate" id="switch" name="switch" value="" onclick="switchUnits()"/>
</div>
一些CSS的
.rotate {
-webkit-transition-duration: 0.8s;
-moz-transition-duration: 0.8s;
-o-transition-duration: 0.8s;
transition-duration: 0.8s;
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
-o-transition-property: -o-transform;
transition-property: transform;
overflow:hidden;
}
.rotate:hover {
-webkit-transform:rotate(180deg);
-moz-transform:rotate(180deg);
-o-transform:rotate(180deg);
}
感謝您的幫助。
編輯:按要求的onClick函數。
function switchUnits(){
//need to get values before swap to and from around.
var from = $("#from").val();
var to = $("#to").val();
//switches the details
$("#to #"+from).attr("selected","selected");
$("#from #"+to).attr("selected","selected");
//gets values after switch
from = $("#from").val();
to = $("#to").val();
//run convert
convertUnits();
}
編輯:非常希望這能夠實現: 可能對於圖像上懸停再次旋轉回到它原來的位置,而不需要點擊它?所以它會是:
在posA,懸停,旋轉,單擊,保持在posB。在posB中, ,懸停,向後旋轉,單擊,再次停留在posA。
的'的onclick = 「switchUnits()」'屬性指向一個JavaScript函數,你應該在你的問題中包含這個函數的代碼。 – mor
@ ricard.m.o。編輯 – null
我只是喜歡CSS3。 –