Raphael的transform用法javascript
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html> <html> <head> <base href="<%=basePath%>"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Title</title> <script type="text/javascript" src="js/jquery-1.11.1.js"></script> <script type="text/javascript" src="js/raphael.js"></script> <script type="text/javascript" src="js/index007.js"></script> </head> <body> <div id="container"></div> </body> </html>
$(function() { initRaphael(); }); function initRaphael(e) { var paper = Raphael(0,0,300,300); var r1 = paper.rect(20,20,80,40).attr('fill','red'); var r2 = paper.rect(100,20,80,40).attr('fill','blue'); var r3 = paper.rect(180,20,80,40).attr('fill','green'); // 以本身的中心爲旋轉點進行旋轉45度 r2.attr('transform','R45'); // 以140,60爲旋轉點進行旋轉90度 r3.attr('transform','R90,140,60'); // 移動至50,60點 r1.attr('transform','T50,60'); // 再移動一次,結果不會累加,只會是下面的結果覆蓋上面的結果; // 並且變換的結果是transform="matrix(1,0,0,1,100,60)",把變換修訂爲變換矩陣; r1.attr('transform','T100,60'); // transform不影響原來的屬性值,這個x仍是20 console.log(r1.attr('x')); // s表示放大 r2.attr('transform','S0.8,0.5'); // 這樣就把全部的transform清空了 // r1.attr('transform',''); // 輸出<rect x="20" y="20" width="80" height="40" rx="0" ry="0" fill="#ff0000" stroke="#000" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);" transform="matrix(1,0,0,1,0,0)"></rect> console.log(r1.node); }