A great option is to use velocity.js, which allows you to modify individual transform properties cumulatively. What sets velocity.js apart is its reliance on JavaScript for animations, rather than jQuery, making it more efficient and avoiding layout thrashing.
var element = document.getElementById("myDiv");
// Set initial transformation upon loading
Velocity(
element,
{
rotateX: '90deg',
rotateY: '10deg'
},
{
duration: 0
});
// Gradually adjust the rotateX property with each click
document.addEventListener("click",function(){
Velocity(
element,
{
translateZ: 0, // Trigger hardware acceleration by animating a 3D property
rotateX: "+=10deg"
},
{
duration: 0
}
);
});
<script src="http://cdnjs.cloudflare.com/ajax/libs/velocity/1.1.0/velocity.min.js"></script>
<div style="width: 200px; height: 200px; background-color: red;" id="myDiv"></div>
If you prefer using jQuery and/or Zepto for their convenient element selection methods, that's also an option:
$(function() {
// Set initial transformation upon loading
$('#myDiv').velocity({
rotateX: '90deg',
rotateY: '10deg'
}, {
duration: 0
});
// Progressively adjust the rotateX property with each click
$('#myDiv').click(function() {
$(this).velocity({
rotateX: '+=10deg'
}, {
duration: 0
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/velocity/1.1.0/velocity.min.js"></script>
<div style="width: 200px; height: 200px; background-color: red;" id="myDiv"></div>