這工作垂直,但我想通過點擊圖像水平旋轉。無法弄清楚這一點!或者也可能有一個更簡單的方法來做到這一點。水平旋轉圖像onClick
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Flip Image</title>
<style>
canvas{border:1px solid #333}
img{display:none;}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script>
<script type="text/javascript">
$(window).load(function(){
var immagine = $('img')[0]
alt=immagine.height
lar=immagine.width
$('<canvas width="'+lar+'" height="'+alt+'"></canvas>').appendTo('body')
var ca=$('canvas').get(0)
ctx=ca.getContext('2d')
ctx.drawImage(immagine, 0, 0);
$('canvas').click(function(){
ctx.translate(lar-1, alt-1);
ctx.rotate(Math.PI);
ctx.drawImage(immagine, 0, 0, lar, alt);
})
})
</script>
</head>
<body>
<!-- onclick rotate image horizontally-->
<img src="myimage.jpg">
<br><Br>
</body>
</html>
謝謝!
這可能有助於http://stackoverflow.com/questions/968642/rotate-image-clockwise-or-anticlockwise -inside-a-div-using-javascript – user2728841