Kopieren Sie den Codecode wie folgt:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<Kopf>
<title>Bildrotationseffekt</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--Fügen Sie den folgenden Code zwischen <head> und </head>--> hinzu
<style type="text/css">
ul{padding:0 15px;}
ul li{padding-bottom:15px;border-bottom:1px dashed #EEE;}
.caption{padding:15px 0 5px;}
.caption input{margin-right:10px;padding:0 10px;}
</style>
<script type="text/javascript">
/*
* www.byzuo.com
* ok!: MSIE 6, 7, 8, Firefox 3.6, Chrome 4, Safari 4, Opera 10
* o Bild-ID drehen;
* p wählt die Drehrichtung aus, der feste Wert ist „links“ oder „rechts“;
*/
Funktion rotieren(o,p){
var img = document.getElementById(o);
if(!img || !p) return false;
var n = img.getAttribute('step');
if(n== null) n=0;
if(p=='right'){
(n==3)? n=0:n++;
}else if(p=='left'){
(n==0)? n=3:n--;
}
img.setAttribute('step',n);
//MSIE
if(document.all) {
img.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation='+ n +')';
//HACK FÜR MSIE 8
switch(n){
Fall 0:
imgimg.parentNode.style.height = img.height;
brechen;
Fall 1:
imgimg.parentNode.style.height = img.width;
brechen;
Fall 2:
imgimg.parentNode.style.height = img.height;
brechen;
Fall 3:
imgimg.parentNode.style.height = img.width;
brechen;
}
//DOM
}anders{
var c = document.getElementById('canvas_'+o);
if(c== null){
img.style.visibility = 'versteckt';
img.style.position = 'absolut';
c = document.createElement('canvas');
c.setAttribute("id",'canvas_'+o);
img.parentNode.appendChild(c);
}
var ccanvasContext = c.getContext('2d');
switch(n) {
Standard :
Fall 0:
c.setAttribute('width', img.width);
c.setAttribute('height', img.height);
canvasContext.rotate(0 * Math.PI / 180);
canvasContext.drawImage(img, 0, 0);
brechen;
Fall 1:
c.setAttribute('width', img.height);
c.setAttribute('height', img.width);
canvasContext.rotate(90 * Math.PI / 180);
canvasContext.drawImage(img, 0, -img.height);
brechen;
Fall 2:
c.setAttribute('width', img.width);
c.setAttribute('height', img.height);
canvasContext.rotate(180 * Math.PI / 180);
canvasContext.drawImage(img, -img.width, -img.height);
brechen;
Fall 3:
c.setAttribute('width', img.height);
c.setAttribute('height', img.width);
canvasContext.rotate(270 * Math.PI / 180);
canvasContext.drawImage(img, -img.width, 0);
brechen;
}
}
}
</script>
</head>
<Körper>
<!--Fügen Sie den folgenden Code zwischen <body> und </body>--> hinzu
<ul>
<li>
<div>
<input type="button" value="turn left" onclick="rotate('pic_1','left')">
<input type="button" value="rechts abbiegen" onclick="rotate('pic_1','right')">
</div>
<div>
<img id="pic_1" src="1.gif">
</div>
</li>
</ul>
</body>
</html>