<scriptlanguage="javascript">
varisIE=(document.uniqueID)?1:0;
vari=1;
functionrotate(image)
{
varobject=image.parentNode;
if(isIE){
image.style.filter="progid:dXImagetransform.Microsoft.basicImage(rotation="+i+")";
i++;
if(i>4){i=1};
}
else{
try{
varcanvas=document.createElement('canvas');
if(canvas.getContext("2d")){
object.replaceChild(canvas,image);
varcontext=canvas.getContext("2d");
context.translate(176,0);
context.rotate(Math.PI*0.5);
context.drawImage(image,0,0);
}
}catch(e){}
}
}
</script>
<imgid="myimg"src="http://www.corange.cn//uploadfiles/0_87641.jpg"/><br/>
<inputtype="button"value="rotate"onclick="rotate(document.getElementById('myimg'))"/>
varisIE=(document.uniqueID)?1:0;
vari=1;
functionrotate(image)
{
varobject=image.parentNode;
if(isIE){
image.style.filter="progid:dXImagetransform.Microsoft.basicImage(rotation="+i+")";
i++;
if(i>4){i=1};
}
else{
try{
varcanvas=document.createElement('canvas');
if(canvas.getContext("2d")){
object.replaceChild(canvas,image);
varcontext=canvas.getContext("2d");
context.translate(176,0);
context.rotate(Math.PI*0.5);
context.drawImage(image,0,0);
}
}catch(e){}
}
}
</script>
<imgid="myimg"src="http://www.corange.cn//uploadfiles/0_87641.jpg"/><br/>
<inputtype="button"value="rotate"onclick="rotate(document.getElementById('myimg'))"/>
本文介绍了一个简单的JavaScript脚本,该脚本可以实现网页上图片的实时旋转效果。通过检测浏览器类型,脚本采用不同的方法来完成图片旋转:对于Internet Explorer使用VML技术;对于其他现代浏览器,则利用HTML5的Canvas API实现。
715

被折叠的 条评论
为什么被折叠?



