Raphael的transform用法
Raphael的transform用法
<%@ 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); }