This article describes the method of implementing the 360-degree flip of the button to control the image. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows: <html>
<title>js implements button control image 360-degree flip effect</title>
<body>
<script language="javascript">
var isIE = (document.uniqueID)?1:0;
var i=1;
function rotate(image)
{
var object = image.parentNode;
if(isIE){
image.style.filter="progid:dXImagetransform.Microsoft.basicImage(rotation="+i+")";
i++;
if(i>4) {i=1};
}
else{
try{
var canvas = document.createElement('canvas');
if(canvas.getContext("2d")) {
object.replaceChild(canvas,image);
var context = canvas.getContext("2d");
context.translate(176, 0);
context.rotate(Math.PI*0.5);
context.drawImage(image,0,0);
}
}catch(e){}
}
}
</script>
<input type="button" value="click to rotate the picture" onclick="rotate(document.getElementById('myimg'))" /><br />
<img id="myimg" src="/images/m03.jpg"/>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.