如果你的想法是離開元素
:在沒有其他選擇,通過點擊返回返回19deg 0deg位置,你可以與去
HTML:
<div id="rotateme">
<p class="clickme">Click Me</p>
</div>
CSS:
#rotateme {
background-color: blue;
width: 200px;
height: 200px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
-webkit-transform: translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(19deg) translate(0px, 0px);
-ms-transform: translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(19deg) translate(0px, 0px);
transform: translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(19deg) translate(0px, 0px);
}
.clickme {
text-align: center;
padding-top: 80px;
color: #fff;
font-size: 20px;
}
的jQuery:
$('.clickme').click(function() {
$("#rotateme").css("-webkit-transform", "translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(0deg) translate(0px, 0px)");
$("#rotateme").css("transform", "translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(0deg) translate(0px, 0px)");
$("#rotateme").css("-ms-transform", "translate3d(382px, 112px, 0px) translate(0px, 0px) rotate(0deg) translate(0px, 0px)");
});
我沒有使用你問,因爲這將推動框中的精確值在可見區域下方(至少在我的眼前)租用Codepen),但你可以看到哪一個需要改變。此外,我正在使用平滑旋轉和前綴過渡,以便它可以在所有現代瀏覽器上運行。
Codepen例子是購here。
您需要做這樣的事情在[這個答案](http://stackoverflow.com/questions/30010523/add-a-transform-value-to-the-current-transforms-that-are-already-上的元件/ 30010571#30010571)。基本上提取當前的變換值,使用正則表達式進行檢查並根據需要進行替換。 – Harry
何時會發生此更改,請點擊?要麼? –
@哈利是的,我確實想到這一點,但希望有一個更簡單的方法! –