ä½¿ç¨ SMIL ç SVG å¨ç»
è¦åï¼è½ç¶ Chrome 45 å¼ç¨äº SMIL èååäº CSS å¨ç»å Web å¨ç»ï¼ä½ä¹å Chrome å¼åè 䏿¢äºå¯¹ SMIL çå¼ç¨ã
Firefox 4 å©ç¨ Synchronized Multimedia Integration Languageï¼SMILï¼å¼å ¥äºå¯¹ SVG å¨ç»çæ¯æãSMIL å è®¸ä½ ï¼
- åå¨ä¸ä¸ªå ç´ çæ°å屿§ï¼xãyâ¦â¦ï¼
- åå¨å形屿§ï¼translation æ rotationï¼
- åå¨é¢è²å±æ§
- ç©ä»¶æ¹åä¸è¿å¨è·¯å¾æ¹å忥
åªè¦å¨ä¸ä¸ª SVG å
ç´ å
æ·»å ä¸ä¸ª SVG å
ç´ æ¯å¦è¯´ <animate>ï¼å°±è½å®ç°è®©å
ç´ å¨èµ·æ¥ãä¸é¢æ¯å个ä¸åæ¹æ³ç示ä¾ã
å ç´ çå¨ç»å±æ§
ä¸é¢ç示ä¾åå¨äºä¸ä¸ªåç cx 屿§ã为äºåå°è¿ï¼æä»¬å¨ <circle> å
ç´ é颿·»å äºä¸ä¸ª <animate> å
ç´ ã对 <animate> å
ç´ æ¥è¯´ï¼éè¦ç屿§æï¼
- attributeName
-
åå¨å±æ§ç屿§åã
- from
-
åå¨çåå§å¼ã
- to
-
ç»æå¼ã
- dur
-
å¨ç»çæç»æ¶é´ï¼ä¾å¦ï¼åâ5sâ代表 5 ç§éï¼ã
å¦æä½ æ³å¨åä¸ä¸ªå
ç´ éå卿´å¤ç屿§ï¼åªè¦æ·»å æ´å¤ç <animate> å
ç´ ã
<svg width="300" height="100">
<title>Attribute Animation with SMIL</title>
<rect x="0" y="0" width="300" height="100" stroke="black" stroke-width="1" />
<circle cx="0" cy="50" r="15" fill="blue" stroke="black" stroke-width="1">
<animate
attributeName="cx"
from="0"
to="500"
dur="5s"
repeatCount="indefinite" />
</circle>
</svg>
åå¨ transform 屿§
<animateTransform> å
ç´ ç¨äºåå¨ transform 屿§ãè¿ä¸ªæ°å
ç´ æ¯å¿
è¦çï¼å¦åæä»¬å°±ä¸è½è®©ä¸ä¸ªç®åçãä»
ä»
æ¯ä¸ä¸ªæ°åç屿§æ¯å¦è¯´ x å¨èµ·æ¥ãæè½¬å±æ§çèµ·æ¥æ¯è¿æ ·çï¼rotation(theta, x, y)ï¼è¿é theta æ¯ä»¥è§åº¦æ°è®¡éçè§åº¦ï¼x å y 齿¯ç»å¯¹ä½ç½®ãå¨ä¸é¢ç示ä¾ä¸ï¼å°åå¨æè½¬çä¸å¿ä»¥åè§åº¦ã
<svg width="300" height="100">
<title>SVG SMIL Animate with transform</title>
<rect x="0" y="0" width="300" height="100" stroke="black" stroke-width="1" />
<rect
x="0"
y="50"
width="15"
height="34"
fill="blue"
stroke="black"
stroke-width="1">
<animateTransform
attributeName="transform"
begin="0s"
dur="20s"
type="rotate"
from="0 60 60"
to="360 100 60"
repeatCount="indefinite" />
</rect>
</svg>
沿çè·¯å¾å¨ç»
<animateMotion> å
ç´ ä½¿ä¸ä¸ªå
ç´ çä½ç½®å¨èµ·æ¥ï¼å¹¶é¡ºçè·¯å¾åæ¥æè½¬ãå®ä¹è¿ä¸ªè·¯å¾æ¯ä¸å¨ <path> å
ç´ ä¸å®ä¹è·¯å¾çæ¹æ³ç¸åãä½ å¯ä»¥è®¾ç½®è¿ä¸ªå±æ§ä»¥å®ä¹å¯¹è±¡æ¯å¦ä¸è·çè·¯å¾çæ£åå¼æè½¬ã
ç¤ºä¾ 1ï¼çº¿æ§è¿å¨
å¨è¿ä¸ªç¤ºä¾ä¸ï¼ä¸ä¸ªèè²çåçå¨å·¦å³è¾¹çä¹é´å¼¹å¨ï¼ä¸æ¬¡å䏿¬¡ï¼æ°¸ä¸åæ¯ãè¿ä¸ªå¨ç»æ¯ç¨ <animateMotion> å
ç´ æçºµçãå¨è¿ä¸ªä¾åä¸ï¼æä»¬å»ºç«äºä¸ä¸ªç± MoveTo å½ä»¤å Horizontal-line å½ä»¤ãZ å½ä»¤ææçè·¯å¾ï¼MoveTo å½ä»¤å½ä»¤æå®å¨ç»è·¯å¾çèµ·å§ç¹ï¼è Horizontal-line å½ä»¤æåç§»å°å³è¾¹ 300 åç´ å¤ï¼Z å½ä»¤éåè·¯å¾ï¼å»ºç«ä¸ä¸ªåå°èµ·å§ç¹çåè·¯ãæ repeatCount 屿§çå¼è®¾ç½®ä¸º indefiniteï¼æä»¬ææäºåå¤å¾ªç¯çå¨ç»ï¼åªè¦ SVG å¾åè¿åå¨å°±ä¼ä¸ç´å¾ªç¯ä¸å»ã
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="100">
<title>SVG SMIL Animate with Path</title>
<rect x="0" y="0" width="300" height="100" stroke="black" stroke-width="1" />
<circle cx="0" cy="50" r="15" fill="blue" stroke="black" stroke-width="1">
<animateMotion path="M 0 0 H 300 Z" dur="3s" repeatCount="indefinite" />
</circle>
</svg>
ç¤ºä¾ 2ï¼æ²çº¿è¿å¨
ç¥ææ¹åç示ä¾ï¼å ¶è¿å¨è·¯å¾æ¯ä¸æ¡æ²çº¿ï¼æ²¿çè·¯å¾çæ¹åè¿å¨ã
<svg width="300" height="100">
<title>SVG SMIL Animate with Path</title>
<rect x="0" y="0" width="300" height="100" stroke="black" stroke-width="1" />
<rect
x="0"
y="0"
width="20"
height="20"
fill="blue"
stroke="black"
stroke-width="1">
<animateMotion
path="M 250,80 H 50 Q 30,80 30,50 Q 30,20 50,20 H 250 Q 280,20,280,50 Q 280,80,250,80Z"
dur="3s"
repeatCount="indefinite"
rotate="auto" />
</rect>
</svg>