图片旋转的小例子

UED TEAM 2010-06-22 13:13:32 累计浏览 3,179 次
<script type="text/javascript">
02 var c1 = document.getElementById("c1");
03 ctx = c1.getContext("2d"),
04 image = document.createElement("IMG");
05 image.onload = function() {
06 c1.width = image.height;
07 c1.height = image.width;
08 ctx.translate(0, image.width);
09 ctx.rotate(270*Math.PI/180);
10 ctx.drawImage(image, 0, 0);
11 }
12 image.src = "http://img1.cache.netease.com/img09/logo/logo_v1.gif";
13 </script>

IE应该用滤镜实现同样的效果。

rotate()这个函数接收的是弧度值。角度乘以0.017(2π/360)可以转变为弧度。

同分类推荐文章

  1. Embracing Playful Imperfection With The CSS `random()` Function (2026-11-14 03:10:02)
  2. Document Picture-in-Picture API与任意元素画中画实现 (2026-11-13 17:10:02)
  3. 给博客做个站内全文搜索:纯前端离线倒排索引的设计与取舍 (2026-10-03 16:40:31)

查看更多 前端 文章 →

建议继续学习

  1. 纯CSS3打造七巧板 (累计阅读 3,346)