Skip to content

Instantly share code, notes, and snippets.

@merih
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merih/a1c648d7c4ae19b264ec to your computer and use it in GitHub Desktop.
Save merih/a1c648d7c4ae19b264ec to your computer and use it in GitHub Desktop.
(function () {
var i = document.querySelector("img"),
r = 0,
m = "<menu type='context' id='m'>" +
"<menuitem label='Rotate clockwise' id='rcw'></menuitem>" +
"<menuitem label='Rotate counter-clockwise' id='rccw'></menuitem>" +
"</menu>";
function rotateBy(d) {
r += d;
i.style.transition = "transform 300ms ease-out";
i.addEventListener("transitionend", function () {
i.style.transition = "";
});
i.style.transform = "rotate(" + r + "deg)";
}
i.insertAdjacentHTML("afterend", m);
document.getElementById("rcw").addEventListener("click", function () {
rotateBy(90);
});
document.getElementById("rccw").addEventListener("click", function () {
rotateBy(-90);
});
i.setAttribute("contextmenu", "m");
})();
@simevidas
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment