精图规范1.0----19 动画 Animation
2014-06-14 20:13
351 查看
next
contents
elements
attributes
properties
index
04September2001
19动画Animation
内容Contents
19.1引言Introduction
因为环球网是一种动态的媒体,精图支持在时间上改变矢量图形的能力.精图内容可以按照下列方式进行动画:BecausetheWebisadynamicmedium,SVGsupportstheabilitytochangevectorgraphicsovertime.SVGcontentcanbeanimatedinthefollowingways:使用精图的
动画元素.精图文档片段可以描述对文档元素进行基于时间的修改.使用各种动画元素,你可以定义运动路径,淡入或淡出效果,以及对象的扩大,收缩,旋转或改变颜色.UsingSVG's
animationelements.SVGdocumentfragmentscandescribetime-basedmodificationstothedocument'selements.Usingthevariousanimationelements,youcandefinemotionpaths,fade-inorfade-outeffects,andobjectsthatgrow,shrink,spinorchangecolor.
使用
精图文档对象模型.精图文档对象模型与"文档对象模型(DOM)级别1"[
其结果是,事实上可以进行任何种类的动画.在脚本语言比如ECMAScript中的时间机制可以用来启动和控制动画.(参见下面的
例子.)Usingthe
SVGDOM.TheSVGDOMconformstokeyaspectsofthe"DocumentObjectModel(DOM)Level1"[
specifications.Everyattributeandstylesheetsettingisaccessibletoscripting,andSVGoffersasetofadditionalDOMinterfacestosupportefficientanimationviascripting.Asaresult,virtuallyanykindofanimationcanbeachieved.Thetimerfacilities
inscriptinglanguagessuchasECMAScriptcanbeusedtostartupandcontroltheanimations.(See
examplebelow.)
精图被设计成允许未来版本的SMIL[
staticSVGcontentasmediacomponents.
在将来,期望未来版本的SMIL将被模块化并且它的组件可以与精图和其它XML语法相结合来完成动画效果.Inthefuture,itisexpectedthatfutureversionsofSMILwillbemodularizedandthatcomponentsofitcouldbeusedinconjunctionwithSVGandotherXMLgrammarstoachieveanimationeffects.
19.2动画元素Animationelements
19.2.1概览Overview
精图动画元素是在与W3C同步多媒体(SYMM)工作组的协作下进行开发的,此开发组即同步多媒体集成语言(SMIL)1.0规范[developersoftheSynchronizedMultimediaIntegrationLanguage(SMIL)1.0Specification[
SYMM工作组,在与精图工作组的协作过程中,已经创作SMIL动画规范[
Group,hasauthoredtheSMILAnimationspecification[
intheSMILAnimationspecificationandprovidessomeSVG-specificextensions.
关于在任何支持SMIL动画的语言中可用的方法与特征的介绍,请参见
SMIL动画概览以及
SMIL动画的动画模型.关于动画之外的动画特征的列表,请参见
对SMIL动画的精图扩展.ForanintroductiontotheapproachandfeaturesavailableinanylanguagethatsupportsSMILAnimation,see
SMILAnimationoverviewand
SMILAnimationanimationmodel.ForthelistofanimationfeatureswhichgobeyondSMILAnimation,see
SVGextensionstoSMILAnimation.
19.2.2与SMIL动画的关系RelationshiptoSMILAnimation
精图是SMIL动画的宿主语言故引入了一些那个规范所允许的增加的约束和特征.除了在此规范中被特别明显地说明的精图特定的规则外,精图的动画元素和性质的正式定义在SMIL动画[introducesadditionalconstraintsandfeaturesaspermittedbythatspecification.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforSVG'sanimationelementsandattributesistheSMILAnimation[
精图支持在SMIL动画规范种定义的四种动画元素:SVGsupportsthefollowingfouranimationelementswhicharedefinedintheSMILAnimationspecification:
允许标量的性质和属性的值随时间不同而指派不同的值allowsscalarattributesandpropertiestobeassigneddifferentvaluesovertime | |||
'animate'的方便的简写,用于对于非数值的性质和属性指派动画值,比如 'visibility'属性aconvenientshorthandfor'animate',whichisusefulforassigninganimationvaluestonon-numericattributesandproperties,suchasthe 'visibility'property | |||
沿着一条运动路径移动一个元素movesanelementalongamotionpath | |||
随着时间的变化而修改特定性质或属性的颜色值modifiesthecolorvalueofparticularattributesorpropertiesovertime |
随着时间的变化而修改精图变换性质之一,比如 transformattribute | |||
精图允许在 path性质中指定的精图的 路径数据语法的特征被指定到 'animateMotion'元素中(SMIL动画仅允许在path性质中精图路径数据语法的一个子集)SVGallowsanyfeaturefromSVG's pathdatasyntaxtobespecifiedina pathattributetothe 'animateMotion'element(SMILAnimationonlyallowsasubsetofSVG'spathdatasyntaxwithinapathattribute) | |||
精图允许一个 'animateMotion'元素包含子 'mpath'元素此元素引用一个精图 'path'元素作为其运动路径的定义SVGallowsan 'animateMotion'elementtocontainachild 'mpath'elementwhichreferencesanSVG 'path'elementasthedefinitionofthemotionpath | |||
精图加入keyPoints性质到 'animateMotion'中以便提供对运动路径动画的速度的精确控制SVGaddsakeyPointsattributetothe 'animateMotion'toprovideprecisecontrolofthevelocityofmotionpathanimations | |||
精图加入 rotate性质到 'animateMotion'中以便控制是否一个对象自动进行旋转使得其x-轴指向与运动路径的方向切向量相同的方向(或相反的方向)SVGaddsa rotateattributetothe 'animateMotion'tocontrolwhetheranobjectisautomaticallyrotatedsothatitsx-axispointsinthesamedirection(oroppositedirection)asthedirectionaltangentvectorofthemotionpath |
xlink:href性质使用
URIreferencesviaan
xlink:hrefattributetoidentifytheelementswhicharetobetargetsoftheanimations.
SMIL动画要求宿主语言定义文档开始和文档结束的含义.因为一个
'svg'有时是XML文档树的根而其它时候又为一个父XML语法的组件,一个给定的精图文档片段的文档开始定义为严格的时间点即
'svg'元素的
onload事件被触发的时间.一个精图文档片段的文档结束The是此点即文档片段被释放并且用户代理不再处理此文档.SMILAnimationrequiresthatthehostlanguagedefinethemeaningfordocumentbeginandthedocumentend.Sincean
'svg'issometimestherootoftheXMLdocumenttreeandothertimescanbeacomponentofaparentXMLgrammar,the
documentbeginforagivenSVGdocumentfragmentisdefinedtobetheexacttimeatwhichthe
'svg'element's
onloadeventistriggered.ThedocumentendofanSVGdocumentfragmentisthepointatwhichthedocumentfragmenthasbeenreleasedandisnolongerbeingprocessedbytheuseragent.
对精图而言,术语表示时间
表示的是相对于给定文档片段的文档开始在时间轴上的位置.ForSVG,thetermpresentationtimeindicatesthepositioninthetimelinerelativetothe
documentbeginofagivendocumentfragment.
精图定义了比在SMIL动画[
错误处理).SVGdefinesmoreconstrainederrorprocessingthanisdefinedintheSMILAnimation[
thedocumentcontinuestorunincertainerrorsituations,whereasallanimationswithinanSVGdocumentfragmentwillstopintheeventofanyerrorwithinthedocument(see
Errorprocessing).
19.2.3动画元素的例子Animationelementsexample
下面的Exampleanim01显示精图的五种动画元素的每一个.Exampleanim01belowdemonstrateseachofSVG'sfiveanimationelements.<?xmlversion="1.0"standalone="no"?>
<!DOCTYPEsvgPUBLIC"-//W3C//DTDSVG20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svgwidth="8cm"height="3cm"viewBox="00800300"
xmlns="http://www.w3.org/2000/svg">
<desc>Exampleanim01-demonstrateanimationelements</desc>
<rectx="1"y="1"width="798"height="298"
fill="none"stroke="blue"stroke-width="2"/>
<!--Thefollowingillustratestheuseofthe'animate'element
toanimatearectanglesx,y,andwidthattributessothat
therectanglegrowstoultimatelyfilltheviewport.-->
<rectid="RectElement"x="300"y="100"width="300"height="100"
fill="rgb(255,255,0)">
<animateattributeName="x"attributeType="XML"
begin="0s"dur="9s"fill="freeze"from="300"to="0"/>
<animateattributeName="y"attributeType="XML"
begin="0s"dur="9s"fill="freeze"from="100"to="0"/>
<animateattributeName="width"attributeType="XML"
begin="0s"dur="9s"fill="freeze"from="300"to="800"/>
<animateattributeName="height"attributeType="XML"
begin="0s"dur="9s"fill="freeze"from="100"to="300"/>
</rect>
<!--Setupanewusercoordinatesystemsothat
thetextstring'soriginisat(0,0),allowing
rotationandscalerelativetotheneworigin-->
<gtransform="translate(100,100)">
<!--Thefollowingillustratestheuseofthe'set','animateMotion',
'animateColor'and'animateTransform'elements.The'text'element
belowstartsoffhidden(i.e.,invisible).At3seconds,it:
*becomesvisible
*continuouslymovesdiagonallyacrosstheviewport
*changescolorfrombluetodarkred
*rotatesfrom-30tozerodegrees
*scalesbyafactorofthree.-->
<textid="TextElement"x="0"y="0"
font-family="Verdana"font-size="35.27"visibility="hidden">
It'salive!
<setattributeName="visibility"attributeType="CSS"to="visible"
begin="3s"dur="6s"fill="freeze"/>
<animateMotionpath="M00L100100"
begin="3s"dur="6s"fill="freeze"/>
<animateColorattributeName="fill"attributeType="CSS"
from="rgb(0,0,255)"to="rgb(128,0,0)"
begin="3s"dur="6s"fill="freeze"/>
<animateTransformattributeName="transform"attributeType="XML"
type="rotate"from="-30"to="0"
begin="3s"dur="6s"fill="freeze"/>
<animateTransformattributeName="transform"attributeType="XML"
type="scale"from="1"to="3"additive="sum"
begin="3s"dur="6s"fill="freeze"/>
</text>
</g>
</svg>
Atzeroseconds | Atthreeseconds | |
Atsixseconds | Atnineseconds | |
Exampleanim01 |
下列章节描述各种动画性质和元素.Thesectionsbelowdescribethevariousanimationattributesandelements.
19.2.4标识动画目标元素的性质Attributestoidentifythetargetelementforananimation
下列性质对所有动画元素是共同的并且用于标识动画目标元素.Thefollowingattributesarecommontoallanimationelementsandidentifythetargetelementfortheanimation.<!ENTITY% "
|
xlink:href="
指向这一动画的目标的元素的
URIreferencetotheelementwhichisthetargetofthisanimationandwhichthereforewillbemodifiedovertime.
目标元素必须是
当前精图文档片段的一部分.Thetargetelementmustbepartofthe
currentSVGdocumentfragment.
<uri>必须指向一个严格的目标元素此元素有能力成为给定动画的目标.如果<uri>指向多个目标元素,如果给定的目标元素不能成为给定的动画的目标,或者如果给定的目标元素不是当前精图文档片段的一部分,那么此文档是错误的(参见
错误处理).<uri>mustpointtoexactlyonetargetelementwhichiscapableofbeingthetargetofthegivenanimation.If<uri>pointstomultipletargetelements,ifthegiventargetelementisnotcapableofbeingatargetofthegivenanimation,orifthe
giventargetelementisnotpartofthecurrentSVGdocumentfragment,thenthedocumentisinerror(see
Errorprocessing).
如果不提供xlink:href性质,那么当前动画元素的直接父元素为其目标元素.Ifthexlink:hrefattributeisnotprovided,thenthetargetelementwillbetheimmediateparentelementofthecurrentanimationelement.
关于何种类型的元素可以成为特定类型动画的目标元素的限制请参考各自动画元素的描述.Refertothedescriptionsoftheindividualanimationelementsforanyrestrictionsonwhattypesofelementscanbetargetsofparticulartypesofanimations.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
指定动画目标.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:Specifyingtheanimationtarget.
在别处定义的性质:Attributesdefinedelsewhere:
19.2.5标识动画目标性质或属性的性质Attributestoidentifythetargetattributeorpropertyforananimation
下列性质用来标识此给定的targetelementwhosevaluechangesovertime.
<!ENTITY% "
|
attributeName=
<attributeName>
指定目标性质的名字.一个XMLNS前缀可以用来表示此性质的XML命名空间.此前缀在当前(即,引用的)动画元素的作用域内进行解释.Specifiesthenameofthetargetattribute.AnXMLNSprefixmaybeusedtoindicatetheXMLnamespacefortheattribute.Theprefixwillbeinterpretedinthescopeofthecurrent(i.e.,
thereferencing)animationelement.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
指定动画目标.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:Specifyingtheanimationtarget.
attributeType="CSS|XML|auto"
指定此目标性质以及它的相关的值被定义的命名空间.性质值为下列之一(值区分大小写):Specifiesthenamespaceinwhichthetargetattributeanditsassociatedvaluesaredefined.Theattributevalueisoneofthefollowing(valuesarecase-sensitive):
"CSS"
这指定"attributeName"的值为在此规范中定义的一个可进行动画的CSS属性的名字.Thisspecifiesthatthevalueof"attributeName"isthenameofaCSSpropertydefinedasanimatableinthisspecification.
"XML"
这指定"attributeName"的值为在缺省XML命名空间中为目标元素定义的一个XML性质的名字.如果
attributeName的值有XMLNS前缀,实现者必须使用此相关的命名空间作为在目标元素的作用域定义的命名空间.在此规范中此性质必须定义为可进行动画的.Thisspecifiesthatthevalueof"attributeName"isthenameofanXMLattributedefinedinthedefault
XMLnamespaceforthetargetelement.Ifthevaluefor
attributeNamehasanXMLNSprefix,theimplementationmustusetheassociatednamespaceasdefinedinthescopeofthetargetelement.Theattributemustbedefinedasanimatableinthisspecification.
"auto"
实现者应该将
attributeName与目标元素的性质相匹配.实现者必须先搜索CSS属性列表看是否有匹配的属性名,如果没有,在缺省的XML命名空间中查找此元素.Theimplementationshouldmatchthe
attributeNametoanattributeforthetargetelement.TheimplementationmustfirstsearchthroughthelistofCSSpropertiesforamatchingpropertyname,andifnoneisfound,searchthedefaultXMLnamespacefortheelement.
缺省值为"auto".Thedefaultvalueis"auto".
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
指定动画目标.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:Specifyingtheanimationtarget.
19.2.6控制动画的播放时间的性质Attributestocontrolthetimingoftheanimation
下列性质对于所有动画元素是共同的它们用于控制动画的播放时间,包含什么情况下动画开始和结束,是否动画重复播放,以及是否一旦动画结束时是否保持动画最后的状态.Thefollowingattributesarecommontoallanimationelementsandcontrolthetimingoftheanimation,includingwhatcausestheanimationtostartandend,whethertheanimationrunsrepeatedly,andwhethertoretaintheendstatetheanimationoncetheanimationends.
<!ENTITY% "
|
S::=(#x20|#x9|#xD|#xA)*
性质定义:Attributedefinitions:
begin:begin-value-list
定义何时元素将开始(即.变成活动).Defineswhentheelementshouldbegin(i.e.becomeactive).
性质值是用分号分隔的值的列表.Theattributevalueisasemicolonseparatedlistofvalues.
begin-value-list::=
begin-value(S?";"S?begin-value-list)?
一个由分号分隔的开始值列表.开始值列表在SMIL动画的章节
"开始和结束时间列表的赋值"上有详细的解释.Asemicolonseparatedlistofbeginvalues.TheinterpretationofalistofbegintimesisdetailedinSMILAnimation'ssectionon
"Evaluationofbeginandendtimelists".
begin-value:(
offset-value|
syncbase-value|
event-value|
repeat-value|
accessKey-value|
wallclock-sync-value|
"indefinite")
描述元素的开始.Describestheelementbegin.
offset-value::=(S?"+"|"-"S?)?(
Clock-value)
对于SMIL动画而言,此值描述此元素的开始用一个隐含的同步基的偏移量来表示.对于精图而言,隐含的同步基开始定义为相对文档的开始.因为在精图中文档的结束总是未确定的,在精图中一个负的偏移量值总是一种错误.ForSMILAnimation,thisdescribestheelementbeginasanoffsetfromanimplicitsyncbase.ForSVG,theimplicitsyncbasebeginisdefinedtobe
relativetothedocumentbegin.SIncethedocumentendinSVGisalwaysundetermined,anegativeoffsetvalueinSVGisalwaysanerror.
syncbase-value::=(Id-value"."("begin"|"end"))(S?("+"|"-")S?
Clock-value)?
描述一个同步基以及一个可选的相对同步基的偏移量.元素的开始定义为相对此开始或另一个动画的结束.一个同步基由一个指向另一个动画元素由要么
begin要么
end标识是否与被引用的动画元素的开始或活动的结束同步的ID引用构成.Describesasyncbaseandanoptionaloffsetfromthatsyncbase.Theelementbeginisdefinedrelativetothebeginoractiveendofanotheranimation.AsyncbaseconsistsofanIDreference
toanotheranimationelementfollowedbyeither
beginor
endtoidentifywhethertosynchronizewiththebeginningoractiveendofthereferencedanimationelement.
event-value::=(Id-value".")?(event-ref)(S?("+"|"-")S?
Clock-value)?
描述一个事件以及一个可选的确定元素开始的偏移量.动画开始定义为相对事件被触发的时间.一给定的基于事件的元素的可用的事件符号的列表是给定元素的由
精图所支持的所有事件的列表可以在
.Describesaneventandanoptionaloffsetthatdeterminetheelementbegin.Theanimationbeginisdefinedrelativetothetimethattheeventisraised.Thelistofevent-symbolsavailableforagivenevent-baseelementisthelistofeventattributesavailable
forthegivenelementasdefinedbythe
SVGDTD,withtheonedifferencethattheleading'on'isremovedfromtheeventname(i.e.,theanimationeventnameis'click',not'onclick').AlistofalleventssupportedbySVGcanbefoundin
Completelistofsupportedevents.Detailsofevent-basedtimingaredescribedin
SMILAnimation:UnifyingEvent-basedandScheduledTiming.
repeat-value::=(Id-value".")?"repeat("integer")"(S?("+"|"-")S?
Clock-value)?
描述一个有条件的重复事件.此元素开始定义为相对于指定反复值的重复事件被触发的时间.Describesaqualifiedrepeatevent.Theelementbeginisdefinedrelativetothetimethattherepeateventisraisedwiththespecifiediterationvalue.
accessKey-value::="accessKey("character")"(S?("+"|"-")S?
Clock-value)?
描述一个确定元素开始的一个accessKey.此元素开始定义为相对于此accessKey字符被用户输入的时间.DescribesanaccessKeythatdeterminestheelementbegin.TheelementbeginisdefinedrelativetothetimethattheaccessKeycharacterisinputbytheuser.
"wallclock-sync-value:wallclock("wallclock-value")"
描述元素开始当一个实时钟时间.实时钟时间的语法基于在[
"indefinite"
动画的开始将由一个"beginElement()"方法调用或者一个目标指向此元素的超链接确定.Thebeginoftheanimationwillbedeterminedbya"beginElement()"methodcallorahyperlinktargetedtotheelement.
动画的DOM方法在
DOMinterfaces.
基于超链接的时间同步在
SMILAnimation:Hyperlinksandtiming.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'begin'attribute.
dur:
Clock-value|"media"|"indefinite"
指定简单的持续时间.Specifiesthesimpleduration.
性质值可以为下列情形之一:Theattributevaluecanbeeitherofthefollowing:
指定在
presentationtime.Valuemustbegreaterthan0.
"media"
指定媒体固有的持续时间作为简单的持续时间.这仅对定义媒体的元素有效.
(对于精图的
动画元素,如果"media"被指定,此性质将被忽略.)Specifiesthesimpledurationastheintrinsicmediaduration.Thisisonlyvalidforelementsthatdefinemedia.
(ForSVG's
animationelements,if"media"isspecified,theattributewillbeignored.)
"indefinite"
指定简单的持续时间为无限.Specifiesthesimpledurationasindefinite.
如果动画无dur性质,那么简单的持续时间为无限.注意如果简单的持续时间为无限那么插补将不工作(虽然这允许对
'set'元素仍然有用).除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.Iftheanimationdoesnothaveadurattribute,thesimpledurationisindefinite.Notethatinterpolationwillnotworkifthesimpledurationisindefinite(althoughthismaystillbeusefulfor
'set'elements).ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'dur'attribute.
end:
end-value-list
定义动画的结束值此值限制活动的持续时间.此性质的值为分号分隔的值的列表.Definesanendvaluefortheanimationthatcanconstraintheactiveduration.Theattributevalueisasemicolonseparatedlistofvalues.
end-value-list::=
end-value(S?";"S?end-value-list)?
分号分隔的结束值的列表.结束时间的列表的详细解释如下.Asemicolonseparatedlistofendvalues.Theinterpretationofalistofendtimesisdetailedbelow.
end-value:(
offset-value|
syncbase-value|
event-value|
repeat-value|
accessKey-value|
wallclock-sync-value|"indefinite")
描述动画的活动结束时间.Describestheactiveendoftheanimation.
值为"indefinite"时指定动画的结束将由一个"endElement()"方法调用确定(动画的DOM方法在
willbedeterminedbya"endElement()"methodcall(theanimationDOMmethodsaredescribedin
DOMinterfaces).
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.
min:
Clock-value|"media"
指定活动期间的最小值.Specifiestheminimumvalueoftheactiveduration.
性质值可以为下列情形之一:Theattributevaluecanbeeitherofthefollowing:
指定活动期间的最小值的长度,按本地时间计量.Specifiesthelengthoftheminimumvalueoftheactiveduration,measuredinlocaltime.
值必须大于0.Valuemustbegreaterthan0.
"media"
指定媒体固有的持续时间作为活动期间的最小值.这仅对定义媒体的元素有效.(对于精图的
动画元素,如果"media"被指定,此性质将被忽略.)Specifiestheminimumvalueoftheactivedurationastheintrinsicmediaduration.Thisisonlyvalidforelementsthatdefinemedia.(ForSVG's
animationelements,if"media"isspecified,theattributewillbeignored.)
min的缺省值为"0".此时完全不对活动期间进行限制.Thedefaultvalueforminis"0".Thisdoesnotconstraintheactivedurationatall.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
foranySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
see
SMILAnimation:'min'attribute.
max:
Clock-value|"media"
指定活动期间的最大值.Specifiesthemaximumvalueoftheactiveduration.
性质值可以为下列情形之一:Theattributevaluecanbeeitherofthefollowing:
指定活动期间的最大值的长度,按本地时间计量.Specifiesthelengthofthemaximumvalueoftheactiveduration,measuredinlocaltime.
值必须大于0.Valuemustbegreaterthan0.
"media"
指定媒体固有的持续时间作为活动期间的最大值.这仅对定义媒体的元素有效.(对于精图的
动画元素,如果"media"被指定,此性质将被忽略.)Specifiesthemaximumvalueoftheactivedurationastheintrinsicmediaduration.Thisisonlyvalidforelementsthatdefinemedia.(ForSVG's
animationelements,if"media"isspecified,theattributewillbeignored.)
max无缺省值.此时完全不对活动期间进行限制.Thereisnodefaultvalueformax.Thisdoesnotconstraintheactivedurationatall.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
foranySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
see
SMILAnimation:'max'attribute.restart:"always"|"whenNotActive"|"never"
always
动画可以在任何时间进行重启.Theanimationcanberestartedatanytime.
此时为缺省值.Thisisthedefaultvalue.
whenNotActive
动画仅当不活动时才可以重启(即.在活动结束之后).试图在动画播放期间重启动画将被忽略.Theanimationcanonlyberestartedwhenitisnotactive(i.e.aftertheactiveend).Attemptstorestarttheanimationduringitsactivedurationareignored.
never
元素不能在父时间容器的当前简单的持续时间的剩余部分内进行重启.(在精图的情况下,因为父时间容器是精图文档片段,故动画不能在文档持续时间的剩余部分内进行重启.)Theelementcannotberestartedfortheremainderofthecurrentsimpledurationoftheparenttimecontainer.(InthecaseofSVG,sincetheparenttimecontaineristheSVG
documentfragment,thentheanimationcannotberestartedfortheremainderofthedocumentduration.)
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'restart'attribute.
repeatCount:numericvalue|"indefinite"
指定动画播放的次数.它可以有下列性质值:Specifiesthenumberofiterationsoftheanimationfunction.Itcanhavethefollowingattributevalues:
numericvalue
这是一种十进制"浮点"数值用于指定循环的次数.它可以包含用分数值表示的部分循环.一个分数值描述
thenumberofiterations.Itcanincludepartialiterationsexpressedasfractionvalues.Afractionalvaluedescribesaportionofthe
simpleduration.Valuesmustbegreaterthan0.
"indefinite"
动画定义为可以无限次重复播放(即.直到文档结束).Theanimationisdefinedtorepeatindefinitely(i.e.untilthedocumentends).
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'repeatCount'attribute.
repeatDur:
Clock-value|"indefinite"
指定重复的整个持续时间.它可以有下列性质值:Specifiesthetotaldurationforrepeat.Itcanhavethefollowingattributevalues:
以
presentationtimetorepeattheanimationfunctionf(t).
"indefinite"
动画定义为可以无限次重复播放(即.直到文档结束).Theanimationisdefinedtorepeatindefinitely(i.e.untilthedocumentends).
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'repeatDur'attribute.
fill:"freeze"|"remove"
这一性质可以取下列值:Thisattributecanhavethefollowingvalues:
freeze
动画效果
SMIL动画:重启动画).Theanimationeffect
F(t)isdefinedtofreezetheeffectvalueatthelastvalueoftheactiveduration.Theanimationeffectis"frozen"fortheremainderofthedocumentduration(oruntiltheanimationisrestarted-see
SMILAnimation:Restartinganimation).
remove
当动画的活动期间过去之后动画效果被去除(不再使用).在动画播放结束后,动画不再对目标发生影响(除非动画被重启-参见
SMIL动画:重启动画).Theanimationeffectisremoved(nolongerapplied)whentheactivedurationoftheanimationisover.Aftertheactiveendoftheanimation,theanimationnolongeraffectsthetarget(unlesstheanimationisrestarted-see
SMILAnimation:Restartinganimation).
Thisisthedefaultvalue.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'fill'attribute.
SMIL动画[
规范中.TheSMILAnimation[
inthisspecification,theSMILAnimation[
Clockvalues
时钟值与SMIL动画[
isrepeatedhere:
Clock-val::=Full-clock-val|Partial-clock-val
|Timecount-val
Full-clock-val::=Hours":"Minutes":"Seconds("."Fraction)?
Partial-clock-val::=Minutes":"Seconds("."Fraction)?
Timecount-val::=Timecount("."Fraction)?(Metric)?
Metric::="h"|"min"|"s"|"ms"
Hours::=DIGIT+;anypositivenumber
Minutes::=2DIGIT;rangefrom00to59
Seconds::=2DIGIT;rangefrom00to59
Fraction::=DIGIT+
Timecount::=DIGIT+
2DIGIT::=DIGITDIGIT
DIGIT::=[0-9]
对于时段值,缺省的度量后缀为"s"(秒).在时钟值中允许非嵌入的空白字符,尽管开始以及尾部的空白字符将被忽略.ForTimecountvalues,thedefaultmetricsuffixis"s"(forseconds).Noembeddedwhitespaceisallowedinclockvalues,althoughleadingandtrailingwhitespacecharacterswillbeignored.
时钟值在
presentationtime.
下面是一些合法时钟值的例子:Thefollowingareexamplesoflegalclockvalues:
完全时钟值:Fullclockvalues:
02:30:03=2hours,30minutesand3seconds
50:00:10.25=50hours,10secondsand250milliseconds
部分时钟值:Partialclockvalue:
02:33=2minutesand33seconds
00:10.5=10.5seconds=10secondsand500milliseconds
时段时钟值:Timecountvalues:
3.2h=3.2hours=3hoursand12minutes
45min=45minutes
30s=30seconds
5ms=5milliseconds
12.467=12secondsand467milliseconds
十进制的小数值正是以秒为单位进行定义的浮点数.于是:Fractionalvaluesarejust(base10)floatingpointdefinitionsofseconds.Thus:
00.5s=500milliseconds
00:00.005=5milliseconds
19.2.7定义时间方面动画值的性质Attributesthatdefineanimationvaluesovertime
下列性质对于元素'animate',
'animateMotion',
'animateColor'和
arecommontoelements
'animate',
'animateMotion',
'animateColor'and
'animateTransform'.Theseattributesdefinethevaluesthatareassignedtothetargetattributeorpropertyovertime.Theattributesbelowprovidecontrolovertherelativetimingofkeyframesandtheinterpolationmethodbetweendiscretevalues.
<!ENTITY% "
|
calcMode="discrete|linear|paced|spline"
指定动画的插补模式.它可以取下列任何值之一.缺省模式为"linear",但是如果性质不支持线性插补(比如.对于字符串而言),此
calcMode性质将被忽略而使用离散插补.Specifiestheinterpolationmodefortheanimation.Thiscantakeanyofthefollowingvalues.Thedefaultmodeis"linear",howeveriftheattribute
doesnotsupportlinearinterpolation(e.g.forstrings),the
calcModeattributeisignoredanddiscreteinterpolationisused.
discrete
此时指定动画函数将不用任何插补从一个值跳到另一个值.Thisspecifiesthattheanimationfunctionwilljumpfromonevaluetothenextwithoutanyinterpolation.
linear
在值之间的简单线性插补用于计算动画函数.除了对
'animateMotion'外,此模式为缺省的
calcMode.Simplelinearinterpolationbetweenvaluesisusedtocalculatetheanimationfunction.Exceptfor
'animateMotion',thisisthedefault
calcMode.
paced
定义在动画播放期间产生匀速改变的插补.只有值定义在线性数值范围内,并且存在某种可以在两点之间计算的类似于"距离"的概念(例如.位置,宽度,高度,等等.)的性质值支持这种模式.如果指定"
paced",任何
keyTimes或
keySplines将被忽略.对于
'animateMotion',这是它的缺省
calcMode.Definesinterpolationtoproduceanevenpaceofchangeacrosstheanimation.Thisisonlysupportedforvaluesthatdefinealinearnumericrange,andforwhichsomenotionof"distance"betweenpointscan
becalculated(e.g.position,width,height,etc.).If"
paced"isspecified,any
keyTimesor
keySplineswillbeignored.For
'animateMotion',thisisthedefault
calcMode.
spline
从取值列表中的一个值到另一个值之间按照由一个三次Bézier样条所定义的时间函数进行插补.此样条的点在
keyTimes性质中定义,并且每个时间间隔的控制点在
keySplines性质中定义.Interpolatesfromonevalueinthe
valueslisttothenextaccordingtoatimefunctiondefinedbyacubicBézierspline.Thepointsofthesplinearedefinedinthe
keyTimesattribute,andthecontrolpointsforeachintervalaredefinedinthe
keySplinesattribute.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'calcMode'attribute.
values="<list>"
一个由分号分隔的一个或多个值的列表.支持
attributeType范围的矢量语法的矢量值性质.除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.Asemicolon-separatedlistofoneormorevalues.Vector-valuedattributesaresupportedusingthevectorsyntaxofthe
attributeTypedomain.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'values'attribute.
keyTimes="<list>"
用来控制动画的步速的一个由分号分隔的时间值的列表.此列表中的每个时间值对应于
values性质列表中的一个值,并且定义此值何时在动画函数中使用.在
keyTimes列表中的每个时间值用0和1(包含)之间的一个浮点数来表示,代表动画元素持续时间的一个比例偏移量.Asemicolon-separatedlistoftimevaluesusedtocontrolthepacingoftheanimation.Each
timeinthelistcorrespondstoavalueinthe
valuesattributelist,anddefineswhenthevalueisusedintheanimationfunction.Eachtimevalueinthe
keyTimeslistisspecifiedasafloatingpointvaluebetween0and1(inclusive),representingaproportionaloffsetintothesimpledurationoftheanimationelement.
如果指定了
keyTimes的一个列表,那么在
keyTimes列表中值的个数要与在
values列表中值的个数完全相同.Ifalistof
keyTimesisspecified,theremustbeexactlyasmanyvaluesinthe
keyTimeslistasinthe
valueslist.
每个后续的时间值必须大于或等于以前的时间值.Eachsuccessivetimevaluemustbegreaterthanorequaltotheprecedingtimevalue.
keyTimes列表的语义依赖于插补模式:The
keyTimeslistsemanticsdependsupontheinterpolationmode:
·对于线性和样条动画而言,列表中的第一个时间值必须为0,并且最后一个时间值必须为1.与每个值相联系的
keyTime定义何时设置此值t;在
keyTimes之间的值被插补.Forlinearandsplineanimation,thefirsttimevalueinthelistmustbe0,andthelasttimevalueinthelistmustbe1.The
keyTimeassociatedwitheachvaluedefineswhenthevalueisset;valuesareinterpolatedbetweenthe
keyTimes.
·对于离散动画而言,列表中的第一个时间值必须为0.与每个值相联系的时间定义何时设置此值;动画函数使用此值直到在
keyTimes中定义的下一个时间来到时为止.Fordiscreteanimation,thefirsttimevalueinthelistmustbe0.Thetimeassociatedwitheachvaluedefineswhenthevalueisset;theanimationfunction
usesthatvalueuntilthenexttimedefinedin
keyTimes.
如果插补模式为"paced",此时将忽略
keyTimes性质.Iftheinterpolationmodeis"paced",the
keyTimesattributeisignored.
如果在
keyTimes说明中存在任何错误(不对的值,值的个数太多或太少),则文档片段是错误的(参见
错误处理).Ifthereareanyerrorsinthe
keyTimesspecification(badvalues,toomanyortoofewvalues),thedocumentfragmentisinerror(see
errorprocessing).
如果简单的持续时间是无限的,则忽略任何
keyTimes说明.Ifthesimpledurationisindefinite,any
keyTimesspecificationwillbeignored.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'keyTimes'attribute.
keySplines="<list>"
一套与
keyTimes列表相关的Bézier控制点,它定义了一个控制时间间隔的步伐的三次Bézier样条函数.性质值是一个由分号分隔的控制点描述的列表.每个控制点描述为一组的四个值:
x1y1x2y2,描述一段时间段的Bézier控制点.定义相关段的
keyTimes值是Bézier"锚点",而
keySplines值是控制点.于是,控制点的数目必须比
keyTimes值的数目少.AsetofBéziercontrolpointsassociatedwiththe
keyTimeslist,definingacubicBézierfunctionthatcontrolsintervalpacing.Theattributevalueisasemicolonseparatedlistofcontrolpointdescriptions.Eachcontrolpointdescriptionisasetoffourvalues:
x1y1x2y2,describingtheBéziercontrolpointsforonetimesegment.The
keyTimesvaluesthatdefinetheassociatedsegmentaretheBézier"anchorpoints",andthe
keySplinesvaluesarethecontrolpoints.Thus,theremustbeonefewersetsofcontrolpointsthanthereare
keyTimes.
值必须在0和1之间.Thevaluesmustallbeintherange0to1.
当
calcMode不为"spline"时将忽略此性质.Thisattributeisignoredunlessthe
calcModeissetto"spline".
如果在
keySplines说明中存在任何错误(不对的值,值的个数太多或太少),则文档片段是错误的(参见
错误处理).Ifthereareanyerrorsinthe
keySplinesspecification(badvalues,toomanyortoofewvalues),thedocumentfragmentisinerror(see
errorprocessing).
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'keySplines'attribute.
from="<value>"
指定动画的开始值.Specifiesthestartingvalueoftheanimation.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'from'attribute.
to="<value>"
指定动画的终止值.Specifiestheendingvalueoftheanimation.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'to'attribute.
by="<value>"
指定动画的相对偏移量值.Specifiesarelativeoffsetvaluefortheanimation.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'by'attribute.
SMIL动画[
规范中.TheSMILAnimation[
mentionedinthisspecification,theSMILAnimation[
在动画元素中指定的动画值必须是指定性质的合法值.开头的或尾部的空白符以及在分号之前或之后的空白符都会被忽略.Theanimationvaluesspecifiedintheanimationelementmustbelegalvaluesforthespecifiedattribute.Leadingandtrailingwhitespace,andwhitespacebeforeandaftersemicolonseparators,will
beignored.
为指定的性质(当在相关的命名空间中定义)所指定的所有值必须是合法的.如果有不合法的值,则文档片段是错误的(参见
错误处理).Allvaluesspecifiedmustbelegalvaluesforthespecifiedattribute(asdefinedintheassociatednamespace).Ifanyvaluesarenotlegal,thedocumentfragmentisinerror(see
errorprocessing).
如果使用值的列表,动画将进行动画的过程中按照顺序使用这些值.如果指定值的列表,则任何from,to和
by性质将被忽略.Ifalistofvaluesisused,theanimationwillapplythevaluesinorderoverthecourseoftheanimation.Ifalistof
valuesisspecified,anyfrom,toandbyattributevaluesareignored.
关于动画变量from/by/to的处理规则在
动画函数值中进行描述.Theprocessingrulesforthevariantsoffrom/by/toanimationsaredescribedin
Animationfunctionvalues.
下列图解解释了
keySplines性质的插补.每个图表解释了单一时间间隔(即在
keyTimes和
values列表的相联系的对偶值之间.)的设置的效果.水平轴可以看作是关于在时间间隔内插补的单位步进的输入值-即沿着给定时间间隔进行插补的步速.垂直轴是单位步进的结果值,通过
keySplines函数的计算来产生.另一个描述方法是水平轴为时间间隔的输入单位时间,
而垂直轴则是输出的单位时间.也可以参见章节
时间间隔和实时钟时间.Thefollowingfigureillustratestheinterpretationofthe
keySplinesattribute.Eachdiagramillustratestheeffectof
keySplinessettingsforasingleinterval(i.e.betweentheassociatedpairsofvaluesinthe
keyTimesand
valueslists.).Thehorizontalaxiscanbethoughtofastheinputvalueforthe
unitprogressofinterpolationwithintheinterval-i.e.thepacewithwhichinterpolationproceedsalongthegiveninterval.Theverticalaxisistheresultingvalueforthe
unitprogress,yieldedbythe
keySplinesfunction.Anotherwayofdescribingthisisthatthehorizontalaxisistheinput
unittimefortheinterval,andtheverticalaxisistheoutputunittime.Seealsothesection
Timingandreal-worldclocktimes.
keySplines="0011"(thedefault) | keySplines=".50.51" | ||
keySplines="0.75.251" | keySplines="10.25.25" | ||
ExamplesofkeySplines |
<animatedur="4s"values="10;20"keyTimes="0;1"
calcMode="spline"keySplines={asintable}/>
上述四种情况所使用的keySplines值,作为动画进行的近似的插补值为:UsingthekeySplinesvaluesforeachofthefourcasesabove,theapproximateinterpolatedvaluesastheanimationproceedsare:
keySplinesvalues | Initialvalue | After1s | After2s | After3s | Finalvalue |
0011 | 10.0 | 12.5 | 15.0 | 17.5 | 20.0 |
.50.51 | 10.0 | 11.0 | 15.0 | 19.0 | 20.0 |
0.75.251 | 10.0 | 18.0 | 19.3 | 19.8 | 20.0 |
10.25.25 | 10.0 | 10.1 | 10.6 | 16.9 | 20.0 |
19.2.8控制动画是否为叠加的性质Attributesthatcontrolwhetheranimationsareadditive
用偏移值或增量值而不用绝对值来定义动画的某个性质的值常常是有用的.一个简单的"生长"动画可以通过将对象的宽度增加10像素来实现:Itisfrequentlyusefultodefineanimationasanoffsetordeltatoanattribute'svalue,ratherthanasabsolutevalues.Asimple"grow"animationcanincreasethewidthofanobjectby10pixels:
<rectwidth="20px"...>
<animateattributeName="width"from="0px"to="10px"dur="10s"
additive="sum"/>
</rect>
在以前的结果的基础上进行重复,累加每次循环的结果常常是有用的.下列例子产生一个在每次循环中不断增长的矩形:Itisfrequentlyusefulforrepeatedanimationstobuilduponthepreviousresults,accumulatingwitheachinteration.Thefollowingexamplecausestherectangletocontinuetogrowwitheachrepeat
oftheanimation:
<rectwidth="20px"...>
<animateattributeName="width"from="0px"to="10px"dur="10s"
additive="sum"accumulate="sum"repeatCount="5"/>
</rect>
在第一次循环结束时矩形的宽度为30像素.在第二次循环结束时矩形的宽度为40像素.在第五次循环结束时矩形的宽度为70像素.Attheendofthefirstrepetition,therectanglehasawidthof30pixels.Attheendofthesecondrepetition,therectanglehasawidthof40pixels.Attheendofthefifthrepetition,
therectanglehasawidthof70pixels.
关于累加动画的更多信息,请参见
SMIL动画:累加动画.关于累加动画的更多信息,请参见
SMIL动画:控制重复动画的行为-累积动画.Formoreinformationaboutadditiveanimations,see
SMILAnimation:Additiveanimation.Formoreinformationoncumulativeanimations,see
SMILAnimation:Controllingbehaviorofrepeatinganimation-Cumulativeanimation.
对于元素
'animate',
'animateMotion',
'animateColor'和
'animateMotion',
'animateColor'and
'animateTransform'.
<!ENTITY% "
|
additive="replace|sum"
控制动画是否叠加.Controlswhetherornottheanimationisadditive.
sum
指定此动画将叠加到性质垫底的值和其它较低优先级的动画上.Specifiesthattheanimationwilladdtotheunderlyingvalueoftheattributeandotherlowerpriorityanimations.
replace
指定此动画将覆盖性质垫底的值和其它较低优先级的动画上.此为缺省值,可是其行为也会受到在
SMIL动画:from,to和by性质如何影响累加行为中描述的性质
by和
to的动画值的影响.Specifiesthattheanimationwilloverridetheunderlyingvalueoftheattributeandotherlowerpriorityanimations.Thisisthedefault,however
thebehaviorisalsoaffectedbytheanimationvalueattributes
byand
to,asdescribedin
SMILAnimation:Howfrom,toandbyattributesaffectadditivebehavior.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'additive'attribute.
accumulate="none|sum"
控制动画是否为累积的.Controlswhetherornottheanimationiscumulative.
sum
指定在第一个之后的每一个重复循环依赖以前循环的最后值.Specifiesthateachrepeatiterationafterthefirstbuildsuponthelastvalueofthepreviousiteration.
none
指定重复循环不累加.Thisisthedefault.Specifiesthatrepeatiterationsarenotcumulative.Thisisthedefault.
当目标性质值不支持加法或者动画元素不重复时,此性质被忽略.Thisattributeisignoredifthetargetattributevaluedoesnotsupportaddition,oriftheanimationelementdoesnotrepeat.
对于"toanimation"累加动画不被定义.Cumulativeanimationisnotdefinedfor"toanimation".
如果动画函数仅由
to性质指定时此性质被忽略.Thisattributewillbeignorediftheanimationfunctionisspecifiedwithonlythe
toattribute.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
性质.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthisattributeistheSMILAnimation[
Inparticular,see
SMILAnimation:'accumulate'attribute.
19.2.9Inheritance
精图允许对性质和属性进行动画.如果一给定的性质或属性被后代所继承,那么在父元素比如'g'元素上的动画具有传播的效果即性质或属性动画值会传给后代元素使其相应的性质或属性具有动画效果;于是,后代元素可以从其祖先处继承动画性质和属性.SVGallowsbothattributesandpropertiestobeanimated.Ifagivenattributeorpropertyisinheritablebydescendants,thenanimationsonaparentelementsuchasa
'g'elementhastheeffectofpropagatingtheattributeorpropertyanimationvaluestodescendantelementsastheanimationproceeds;thus,descendantelementscaninheritanimatedattributesandpropertiesfromtheirancestors.
19.2.10'animate'元素The'animate'element
'animate'元素用来对一个单一的性质或属性随时间进行动画.例如,为了在5秒内重复地将一个矩形淡出,你可以指定:The'animate'elementisusedtoanimateasingleattributeorpropertyovertime.Forexample,tomakearectanglerepeatedlyfadeawayover5seconds,youcanspecify:<rect>
<animateattributeType="CSS"attributeName="opacity"
from="1"to="0"dur="5s"repeatCount="indefinite"/>
</rect>
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
元素.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthiselementistheSMILAnimation[
Inparticular,see
SMILAnimation:'animate'element.
<!ENTITY%animateExt""> <!ELEMENT <!ATTLIST
|
externalResourcesRequired,
关于可以使用'animate'元素进行动画的性质和属性的列表,参见
能够进行动画的元素,性质和属性.Foralistofattributesandpropertiesthatcanbeanimatedusingthe'animate'element,see
Elements,attributesandpropertiesthatcanbeanimated.
19.2.11'set'元素The'set'element
'set'元素提供在特定持续时间内正好设置一个性质的值的一种简单方法.它支持所有性质类型,包括那些绝对不能进行插补的性质,比如字符串和布尔值.'set'元素是不能叠加的.不允许叠加和累积的性质,并且即使指定这种类型的性质也会被忽略掉.The'set'elementprovidesasimplemeansofjustsettingthevalueofanattributeforaspecifiedduration.Itsupportsallattributetypes,includingthosethatcannotreasonablybeinterpolated,suchasstringandbooleanvalues.The'set'elementisnon-additive.Theadditiveandaccumulateattributesarenotallowed,andwillbeignoredifspecified.
除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
Inparticular,see
SMILAnimation:'set'element.
<!ENTITY%setExt""> <!ELEMENT <!ATTLIST
|
to="<value>"
指定在'set'元素的持续时间内此性质的值.参数值必须与性质类型相匹配.Specifiesthevaluefortheattributeduringthedurationofthe'set'element.Theargumentvaluemustmatchtheattributetype.
在别处定义的性质:Attributesdefinedelsewhere:
externalResourcesRequired,
关于可以使用'set'元素进行动画的性质和属性的列表,参见
能够进行动画的元素,性质和属性.Foralistofattributesandpropertiesthatcanbeanimatedusingthe'set'element,see
Elements,attributesandpropertiesthatcanbeanimated.
19.2.12'animateMotion'元素The'animateMotion'element
'animateMotion'元素使一个引用元素沿着一条移动路径移动.The'animateMotion'elementcausesareferencedelementtomovealongamotionpath.除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
元素.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthiselementistheSMILAnimation[
Inparticular,see
SMILAnimation:'animateMotion'element.
<!ENTITY%animateMotionExt""> <!ELEMENT <!ATTLIST
|
calcMode="discrete|linear|paced|spline"
指定动画的插补模式.参见上述
calcMode性质的一般描述.唯一的不同是'animateMotion'的calcMode的缺省值为paced.参见
SMIL动画:'animateMotion'的'calcMode'性质.Specifiestheinterpolationmodefortheanimation.Refertogeneraldescriptionofthe
calcModeattributeabove.TheonlydifferenceisthatthedefaultvalueforthecalcModefor'animateMotion'ispaced.See
SMILAnimation:'calcMode'attributefor'animateMotion'.
path="<path-data>"
移动路径,与
'path'元素的
inthesameformatandinterpretedthesamewayasthe
d=attributeonthe
'path'element.TheeffectofamotionpathanimationistoaddasupplementaltransformationmatrixontotheCTMforthereferencedobjectwhichcausesatranslationalongthex-andy-axesofthecurrentusercoordinatesystembythecomputedXandYvalues
computedovertime.
keyPoints="<list-of-numbers>"
keyPoints接受用分号分隔的取值介于0和1之间浮点数列表并且表示在由对应的keyTimes值所指定的时间的瞬间此对象沿着移动路径移动了多远.距离的计算使用用户代理的
沿着路径的距离算法.在列表中每个前进值对应
keyTimes性质列表中的一个值.keyPointstakesasemicolon-separatedlistoffloatingpointvaluesbetween0and1andindicateshowfaralongthemotionpaththeobjectshallmoveatthemomentintimespecifiedbycorrespondingkeyTimes
value.Distancecalculationsusetheuseragent's
distancealongthepathalgorithm.Eachprogressvalueinthelistcorrespondstoavalueinthe
keyTimesattributelist.
如果指定了列表
keyPoints,那么在
keyPoints列表中值的个数必须与
keyTimes列表中值的个数相同.Ifalistof
keyPointsisspecified,theremustbeexactlyasmanyvaluesinthe
keyPointslistasinthe
keyTimeslist.
如果在
keyPoints说明中存在任何错误(不对的值,值的个数太多或太少),则文档片段是错误的(参见
错误处理).Ifthereareanyerrorsinthe
keyPointsspecification(badvalues,toomanyortoofewvalues),thenthedocumentisinerror(see
Errorprocessing).
rotate="<angle>|auto|auto-reverse"
auto表示对象根据移动路径的方向(即,切向量方向)的角度随着时间进行旋转.auto-reverse表示对象根据移动路径的方向(即,切向量方向)的角度加上180度随着时间进行旋转.也可以给定一个实际的角度值,它表示相对于当前用户坐标系的x轴的角度.rotate性质将一个额外的变换矩阵加到CTM中来实现对当前用户坐标系的原点的旋转变换.旋转变换在由
path性质所进行计算的平移变换之后进行.缺省值为0.autoindicatesthattheobjectisrotatedovertimebytheangleofthedirection(i.e.,directionaltangentvector)ofthemotionpath.auto-reverseindicatesthattheobjectisrotatedovertimebytheangleofthedirection(i.e.,
directionaltangentvector)ofthemotionpathplus180degrees.Anactualanglevaluecanalsobegiven,whichrepresentsananglerelativetothex-axisofcurrentusercoordinatesystem.Therotateattributeaddsasupplementaltransformationmatrixontothe
CTMtoapplyarotationtransformationabouttheoriginofthecurrentusercoordinatesystem.Therotationtransformationisappliedafterthesupplementaltranslationtransformationthatiscomputedduetothe
pathattribute.Thedefaultvalueis0.
origin="default"
origin性质在SMIL动画规范[
hasnoeffectinSVG.
在别处定义的性质:Attributesdefinedelsewhere:
externalResourcesRequired,
to,
by,
%animAdditionAttrs;.
<!ENTITY%mpathExt""> <!ELEMENT <!ATTLIST
|
xlink:href="
A
URIreferencetothe
'path'elementwhichdefinesthemotionpath.
在别处定义的性质:Attributesdefinedelsewhere:
对于'animateMotion',
from,
by,
to和
values所指定的值由x,y坐标值偶构成,x坐标和y坐标之间用逗号或空白符分隔.例如,from="33,15"指定x坐标值为33而y坐标值为15.For'animateMotion',thespecifiedvaluesfor
from,
by,
toand
valuesconsistsofx,ycoordinatepairs,withasinglecommaand/orwhitespaceseparatingthexcoordinatefromtheycoordinate.Forexample,from="33,15"specifiesanxcoordinatevalueof33andaycoordinatevalueof15.
如果提供
values性质它必须由x,y坐标偶的列表所组成.坐标值之间用至少一个空白符或一个逗号分隔.分隔符周围多余的空白符是允许的.例如,values="10,20;30,20;30,40"或values="10mm,20mm;30mm,20mm;30mm,40mm".每个坐标表示一
长度.性质
from,
by,
to和
values指定当前画布上的一个表示移动路径的形状.Ifprovided,the
valuesattributemustconsistsofalistofx,ycoordinatepairs.Coordinatevaluesareseparatedbyatleastonewhitespacecharacteroracomma.Additionalwhitespacearoundtheseparatorisallowed.Forexample,values="10,20;30,20;30,40"orvalues="10mm,20mm;30mm,20mm;30mm,40mm".Each
coordinaterepresentsa
length.Attributes
from,
by,
toand
valuesspecifyashapeonthecurrentcanvaswhichrepresentsthemotionpath.
可用两种通过使用精图的
pathdatacommands:
the
pathattributedefinesamotionpathdirectlyon
'animateMotion'elementusinganyofSVG's
pathdatacommands.
'mpath'子元素提供一种引用一个外部
'mpath'sub-elementprovidestheabilitytoreferenceanexternal
'path'elementasthedefinitionofthemotionpath.
注意精图的
from,
by,
to和
values既可在用户空间中指定坐标也可以使用单位标识符.参见
单位.NotethatSVG's
pathdatacommandscanonlycontainvaluesinuserspace,whereas
from,
by,
toand
valuescanspecifycoordinatesinuserspaceorusingunitidentifiers.See
Units.
形状的各种(x,y)点为引用的对象提供了一个附加的变换矩阵到CTM上它通过随时计算形状的(x,y)值生成一个沿着当前用户坐标系的x-和y-轴所进行的平移.于是,引用对象通过相对于当前用户坐标系的原点的偏移量随时进行平移.此附加变换被用在任何由于目标元素的
transform性质或者任何在此性质上的动画由于在目标元素上的
offsetofthemotionpathrelativetotheoriginofthecurrentusercoordinatesystem.Thesupplementaltransformationisappliedontopofanytransformationsduetothetargetelement's
transformattributeoranyanimationsonthatattributedueto
'animateTransform'elementsonthetargetelement.
性质用于'animateMotion'元素.都同时引用一个相同的目标元素的多个'animateMotion'元素可以相互叠加;可是,从'animateMotion'元素所导致的变换总是追加到目标元素的
transform性质或者
additiveand
accumulateattributesapplytoelements.Multiple'animateMotion'elementsallsimultaneouslyreferencingthesametargetelementcanbeadditivewithrespecttoeachother;however,thetransformationswhichresultfromthe'animateMotion'elementsarealways
supplementaltoanytransformationsduetothetargetelement'stransformattributeorany
'animateTransform'elements.
animateMotion的缺省计算模式(calcMode)是"paced".这会产生沿着指定的路径的匀速运动.注意animateMotion元素可以叠加时,注意到两个或更多"paced"(匀速)动画的叠加也许不能生成一个匀速的组合的运动动画是重要的.Thedefaultcalculationmode(calcMode)foranimateMotionis"paced".Thiswillproduceconstantvelocitymotion
alongthespecifiedpath.NotethatwhileanimateMotionelementscanbeadditive,itisimportanttoobservethattheadditionoftwoormore"paced"(constantvelocity)animationsmightnotresultinacombinedmotionanimationwithconstantvelocity.
当path与"discrete","linear"或"spline"calcMode设置相结合时,并且如果不提供性质keyPoints,值的数目由此路径的点的数目来定义,除非在此路径中有一个"moveto"命令.在此path中的"moveto"命令(即除了此path描述的开始)一个"moveto"命令不算作一个追加的点当划分持续时间时,或者当与
keyTimes,
keySplines和
keyPoints的值相联系时.当path与一个"paced"calcMode设置相结合时,所有"moveto"命令被认为具有长度0(即它们是在瞬间发生的),并且在计算进步时不加考虑.Whenapathiscombinedwith"discrete","linear"or"spline"calcModesettings,andif
attributekeyPointsisnotprovided,thenumberofvaluesisdefinedtobethenumberofpointsdefinedbythepath,unlessthereare"moveto"commandswithinthepath.A"moveto"commandwithinthepath(i.e.otherthanatthebeginningofthepathdescription)A
"moveto"commanddoesnotcountasanadditionalpointwhendividinguptheduration,orwhenassociating
keyTimes,
keySplinesand
keyPointsvalues.Whenapathiscombinedwitha"paced"calcModesetting,all"moveto"commandsareconsideredtohave0length(i.e.theyalwayshappeninstantaneously),andisnotconsideredincomputingthepacing.
为了在控制沿着移动路径的速度时较灵活,keyPoints性质提供了为每个
keyTimes使用keyPoints中的值而不是在values性质数组中指定的值也不是path性质中的点.Formoreflexibilityincontrollingthevelocityalongthemotionpath,the
keyPointsattributeprovidestheabilitytospecifytheprogressalongthemotionpathforeachofthe
keyTimesspecifiedvalues.Ifspecified,keyPointscauseskeyTimestoapplytothevaluesinkeyPointsratherthanthepointsspecifiedinthevaluesattributearrayorthepointsonthepathattribute.
关于'animateMotion'的覆盖规则说明如下.注意移动路径的定义,
'mpath'元素覆盖path性质,而path覆盖values,而values覆盖from/by/to.注意对应于keyTimes性质的点的确定,keyPoints性质覆盖path,而path覆盖values,而values覆盖from/by/to.Theoverriderulesfor'animateMotionareasfollows.Regardingthedefinitionofthemotionpath,the
'mpath'elementoverridesthethepathattribute,whichoverridesvalues,whichoverridesfrom/by/to.RegardingdeterminingthepointswhichcorrespondtothekeyTimesattributes,thekeyPointsattributeoverridespath,whichoverridesvalues,whichoverrides
from/by/to.
在持续时间dur的一个移动路径动画的任何时间t,沿着移动路径计算的坐标(x,y)是由找到的点(x,y)确定的它是由
t/dur使用用户代理的
沿着路径的距离算法求出的沿着移动路径的距离.???Atanytimetwithinamotionpathanimationofduration
dur,thecomputedcoordinate(x,y)alongthemotionpathisdeterminedbyfindingthepoint(x,y)whichis
t/durdistancealongthemotionpathusingtheuseragent's
distancealongthepathalgorithm.
下列例子说明在一个移动路径动画期间额外的变换矩阵被计算.Thefollowingexampledemonstratesthesupplementaltransformationmatricesthatarecomputedduringamotionpathanimation.
ExampleanimMotion01显示一个沿一个移动路径运动的三角形.ExampleanimMotion01showsatrianglemovingalongamotionpath.
<?xmlversion="1.0"standalone="no"?>
<!DOCTYPEsvgPUBLIC"-//W3C//DTDSVG20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svgwidth="5cm"height="3cm"viewBox="00500300"
xmlns="http://www.w3.org/2000/svg">
<desc>ExampleanimMotion01-demonstratemotionanimationcomputations</desc>
<rectx="1"y="1"width="498"height="298"
fill="none"stroke="blue"stroke-width="2"/>
<!--Drawtheoutlineofthemotionpathinblue,along
withthreesmallcirclesatthestart,middleandend.-->
<pathd="M100,250C100,50400,50400,250"
fill="none"stroke="blue"stroke-width="7.06"/>
<circlecx="100"cy="250"r="17.64"fill="blue"/>
<circlecx="250"cy="100"r="17.64"fill="blue"/>
<circlecx="400"cy="250"r="17.64"fill="blue"/>
<!--Hereisatrianglewhichwillbemovedaboutthemotionpath.
Itisdefinedwithanuprightorientationwiththebaseof
thetrianglecenteredhorizontallyjustabovetheorigin.-->
<pathd="M-25,-12.5L25,-12.5L0,-87.5z"
fill="yellow"stroke="red"stroke-width="7.06">
<!--Definethemotionpathanimation-->
<animateMotiondur="6s"repeatCount="indefinite"
path="M100,250C100,50400,50400,250"rotate="auto"/>
</path>
</svg>
Atzeroseconds | Atthreeseconds | Atsixseconds | ||
ExampleanimMotion01 |
下列表格显示使用额外的变换矩阵达到移动路径动画的效果.Thefollowingtableshowsthesupplementaltransformationmatricesthatareappliedtoachievetheeffectofthemotionpathanimation.
After0s | After3s | After6s | |
Supplementaltransform duetomovement alongmotionpath | translate(100,250) | translate(250,100) | translate(400,250) |
Supplementaltransform dueto rotate="auto" | rotate(-90) | rotate(0) | rotate(90) |
可以进行动画的元素,性质和属性.Foralistofelementsthatcanbeanimatedusingthe'animateMotion'element,see
Elements,attributesandpropertiesthatcanbeanimated.
19.2.13'animateColor'元素The'animateColor'element
'animateColor'元素指定一种随时间的颜色变化.The'animateColor'elementspecifiesacolortransformationovertime.除了在此规范中被特别明显地说明的精图特定的规则外,这一性质的正式定义在SMIL动画[
元素.ExceptforanySVG-specificrulesexplicitlymentionedinthisspecification,thenormativedefinitionforthiselementistheSMILAnimation[
Inparticular,see
SMILAnimation:'animateColor'element.
<!ENTITY%animateColorExt""> <!ELEMENT <!ATTLIST
|
externalResourcesRequired,
from,
by和
to性质取颜色值,这里每个颜色值用下列语法表示(与精图中可以取颜色值的属性所用的语法相同):The
from,
byand
toattributestakecolorvalues,whereeachcolorvalueisexpressedusingthefollowingsyntax(thesamesyntaxasusedinSVG'spropertiesthatcantakecolorvalues):
<color>[icc-color(<name>[,<icccolorvalue>]*)]
'animateColor'元素的
values性质由用分号分隔的颜色值列表构成,此列表中的每个颜色值用上述语法表示.The
valuesattributeforthe'animateColor'elementconsistsofasemicolon-separatedlistofcolorvalues,witheachcolorvalueexpressedintheabovesyntax.
可以提供超出范围的颜色值,可是用户代理的处理将会依赖于特定的实现.用户代理尽可能在最后钳制颜色值为允许的颜色值,可是注意到系统的差别也许会导致不同的系统的不一致的行为.Outofrangecolorvaluescanbeprovided,butuseragentprocessingwillbeimplementationdependent.Useragentsshouldclampcolorvaluestoallowcolorrangevalues
aslateaspossible,butnotethatsystemdifferencesmightprecludeconsistentbehavioracrossdifferentsystems.
'color-interpolation'propertyappliestocolorinterpolationsthatresultfrom'animateColor'animations.
关于可用'animateColor'元素进行动画的性质和属性的列表,请参见
可以进行动画的元素,性质和属性.Foralistofattributesandpropertiesthatcanbeanimatedusingthe'animateColor'element,see
Elements,attributesandpropertiesthatcanbeanimated.
19.2.14'animateTransform'元素The'animateTransform'element
'animateTransform'元素对目标元素的一个变换性质进行动画,因此允许动画控制平移,缩放,旋转以及歪斜.The'animateTransform'elementanimatesatransformationattributeonatargetelement,therebyallowinganimationstocontroltranslation,scaling,rotationand/orskewing.<!ENTITY%animateTransformExt""> <!ELEMENT <!ATTLIST
|
type="translate|scale|rotate|skewX|skewY"
表示值随时间变化的变换的类型.Indicatesthetypeoftransformationwhichistohaveitsvalueschangeovertime.
在别处定义的性质:Attributesdefinedelsewhere:
externalResourcesRequired,
from,
by和
to性质取为给定变换类型可用的相同语法表示的值:The
from,
byand
toattributestakeavalueexpressedusingthesamesyntaxthatisavailableforthegiventransformationtype:
对于type="translate",每个单独的值表示为<tx>[,<ty>].Foratype="translate",eachindividualvalueisexpressedas<tx>[,<ty>].
对于type="scale",每个单独的值表示为<sx>[,<sy>].Foratype="scale",eachindividualvalueisexpressedas<sx>[,<sy>].
对于type="rotate",每个单独的值表示为<rotate-angle>[<cx><cy>].Foratype="rotate",eachindividualvalueisexpressedas<rotate-angle>[<cx><cy>].
对于type="skewX"和type="skewY",每个单独的值表示为<skew-angle>.Foratype="skewX"andtype="skewY",eachindividualvalueisexpressedas<skew-angle>.
(参见transform
'animateTransform'元素的
values性质由一个分号分隔的值的列表组成,这里每个单独的值以上述
by和
to所描述的方式来表示.The
valuesattributeforthe'animateTransform'elementconsistsofasemicolon-separatedlistofvalues,whereeachindividualvalueisexpressedasdescribedabovefor
from,
byand
to.
如果
calcMode的值为paced,那么变换的每个部份的整个被计算的"距离"(例如,对于一个平移操作,关于tx和ty的整个被计算的距离)由每个值偶之间的差的绝对值的和所组成,并且动画播放时为每个单独的部分产生一个等距的运动.???If
calcModehasthevaluepaced,thenatotal"distance"foreachcomponentofthetransformationiscalculated(e.g.,foratranslateoperation,atotaldistanceiscalculatedforboth
txandty)consistingofthesumoftheabsolutevaluesofthedifferencesbetweeneachpairofvalues,andtheanimationrunstoproduceaconstantdistancemovementforeachindividualcomponent.
当一个动画活动时,非叠加(即,additive="replace")'animateTransform'的效果为用由'animateTransform'定义的变换所得出的值替换给定的性质的值.叠加(即,additive="sum")的效果为后乘以由这一'animateTransform'定义的变换所对应的变换矩阵.为了说明:Whenananimationisactive,theeffectofnon-additive'animateTransform'(i.e.,
additive="replace")istoreplacethegivenattribute'svaluewiththetransformationdefinedbythe'animateTransform'.Theeffectofadditive(i.e.,additive="sum")istopost-multiplythetransformationmatrixcorrespondingtothetransformationdefinedby
this'animateTransform'.Toillustrate:
<recttransform="skewX(30)"...>
<animateTransformattributeName="transform"attributeType="XML"
type="rotate"from="0"to="90"dur="5s"
additive="replace"fill="freeze"/>
<animateTransformattributeName="transform"attributeType="XML"
type="scale"from="1"to="2"dur="5s"
additive="replace"fill="freeze"/>
</rect>
在上面一小段代码中,因为两个动画都具有性质additive="replace",第一个动画覆盖矩形本身的变换而第二个动画又覆盖第一个动画的变换;因此,在时间为5秒的时候,上述两个动画的视觉结果等价于下列静止的矩形:Inthecodesnippetabove,becausethebothanimationshaveadditive="replace",thefirstanimationoverridesthetransformationontherectangle
itselfandthesecondanimationoverridesthetransformationfromthefirstanimation;therefore,attime5seconds,thevisualresultoftheabovetwoanimationswouldbeequivalenttothefollowingstaticrectangle:
<recttransform="scale(2)".../>
而在下列例子中:whereasinthefollowingexample:
<recttransform="skewX(30)"...>
<animateTransformattributeName="transform"attributeType="XML"
type="rotate"from="0"to="90"dur="5s"
additive="sum"fill="freeze"/>
<animateTransformattributeName="transform"attributeType="XML"
type="scale"from="1"to="2"dur="5s"
additive="sum"fill="freeze"/>
</rect>
在这一小段代码中,因为两个动画都具有性质additive="sum",第一个动画将其变换后乘矩形本身的任何变换并且第二个动画将其变换后乘第一个动画得到的任何变换;因此,在时间为5秒的时候,上述两个动画的视觉结果等价于下列静止的矩形:Inthiscodesnippet,becausethebothanimationshaveadditive="sum",thefirstanimationpost-multipliesitstransformationtoanytransformationsontherectangleitselfandthesecondanimationpost-multipliesitstransformationtoanytransformationfromthefirstanimation;therefore,attime5seconds,thevisualresultoftheabovetwoanimationswouldbeequivalenttothefollowingstatic
rectangle:
<recttransform="skewX(30)rotate(90)scale(2)".../>
关于可用'animateTransform'元素进行动画的性质和属性的列表,请参见
可以进行动画的元素,性质和属性.Foralistofattributesandpropertiesthatcanbeanimatedusingthe'animateTransform'element,see
Elements,attributesandpropertiesthatcanbeanimated.
19.2.15可以进行动画的元素,性质和属性Elements,attributesandpropertiesthatcanbeanimated
下面列出了所有可以被'animateMotion'element:
在此规范中的每一个性质或属性标明了精图的动画元素对其是否可以进行动画.可以动画的性质和属性标明如下:EachattributeorpropertywithinthisspecificationindicateswhetherornotitcanbeanimatedbySVG'sanimationelements.Animatableattributes
andpropertiesaredesignatedasfollows:
Animatable:yes.
反之不能进行动画的性质和属性标明如下:whereasattributesandpropertiesthatcannotbeanimatedaredesignated:
Animatable:no.
精图为其所支持的各种各样性质和属性定义了一套
可是,如果随后的动画使用关键词值,叠加动画是不可能的.SVGhasadefinedsetof
basicdatatypesforitsvarioussupportedattributesandproperties.Forthoseattributesandpropertiesthatcanbeanimated,thefollowingtableindicateswhichanimationelementscanbeusedtoanimateeachofthebasicdatatypes.Ifagivenattribute
orpropertycantakevaluesofkeywords(whicharenotadditive)ornumericvalues(whichareadditive),thenadditiveanimationsarepossibleifthesubsequentanimationusesanumericvalueevenifthebaseanimationusesakeywordvalue;however,ifthesubsequent
animationusesakeywordvalue,additiveanimationisnotpossible.
Datatype | Additive? | 'animate Color' | 'animate Transform' | Notes | ||
yes | yes | yes | no | no | ||
yes | yes | yes | yes | no | OnlyRGBcolorvaluesareadditive. | |
yes | yes | yes | no | no | ||
no | no | no | no | no | ||
yes | yes | yes | no | no | ||
yes | yes | yes | no | no | ||
no | yes | yes | no | no | ||
yes | yes | yes | no | no | ||
yes | yes | yes | yes | no | OnlyRGBcolorvaluesareadditive. | |
yes | yes | yes | no | no | ||
no | no | no | no | no | ||
yes | no | no | no | yes | Additivemeansthatatransformationispost-multipliedtothebasesetoftransformations. | |
no | yes | yes | no | no | ||
Allotherdatatypesusedinanimatableattributesandproperties | no | yes | yes | no | no |
orpropertyisdefined.
19.3使用精图文档对象模型进行动画AnimationusingtheSVGDOM
Exampledom01显示了一个使用文档对象模型进行动画的简单例子.Exampledom01showsasimpleanimationusingtheDOM.<?xmlversion="1.0"standalone="no"?>
<!DOCTYPEsvgPUBLIC"-//W3C//DTDSVG20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svgwidth="4cm"height="2cm"viewBox="00400200"
xmlns="http://www.w3.org/2000/svg"
onload="StartAnimation(evt)">
<scripttype="text/ecmascript"><![CDATA[
vartimevalue=0;
vartimer_increment=50;
varmax_time=5000;
vartext_element;
functionStartAnimation(evt){
text_element=evt.target.ownerDocument.getElementById("TextElement");
ShowAndGrowElement();
}
functionShowAndGrowElement(){
timevalue=timevalue+timer_increment;
if(timevalue>max_time)
return;
//Scalethetextstringgraduallyuntilitis20timeslarger
scalefactor=(timevalue*20.)/max_time;
text_element.setAttribute("transform","scale("+scalefactor+")");
//Makethestringmoreopaque
opacityfactor=timevalue/max_time;
text_element.setAttribute("opacity",opacityfactor);
//CallShowAndGrowElementagain<timer_increment>millisecondslater.
setTimeout("ShowAndGrowElement()",timer_increment)
}
window.ShowAndGrowElement=ShowAndGrowElement
]]></script>
<rectx="1"y="1"width="398"height="198"
fill="none"stroke="blue"stroke-width="2"/>
<gtransform="translate(50,150)"fill="red"font-size="7">
<textid="TextElement">SVG</text>
</g>
</svg>
Atzeroseconds | At2.5seconds | Atfiveseconds | ||
Exampledom01 |
上述精图文件包含一个单独的图形元素,一个为"SVG"的文本字符串.动画循环了5秒.文本字符串开始时较小并且是透明的逐渐增长为较大和不透明.这里是这一例子如何工作的说明:TheaboveSVGfilecontainsasinglegraphicselement,atextstringthatsays"SVG".Theanimationloopsfor5seconds.Thetextstringstartsoutsmallandtransparent
andgrowstobelargeandopaque.Hereisanexplanationofhowthisexampleworks:
onload="StartAnimation(evt)"性质表示,一旦文档完全加载并且被处理,调用ECMAScript函数
StartAnimation.The
onload="StartAnimation(evt)"attributeindicatesthat,oncethedocumenthasbeenfullyloadedandprocessed,invokeECMAScriptfunction
StartAnimation.
'script'元素定义ECMAScript此脚本生成将播放的动画.
StartAnimation()函数仅调用一次来给全局变量
text_element赋值并执行
ShowAndGrowElement()的首次调用.每隔50毫秒调用一次
ShowAndGrowElement()并且在每次调用时重新设置此文本元素的
transform和
style性质的值.在
ShowAndGrowElement的末尾,函数告诉ECMAScript引擎在50毫秒之后再次调用本身.The'script'elementdefinestheECMAScriptwhichmakestheanimationhappen.The
StartAnimation()functionisonlycalledoncetogiveavaluetoglobalvariable
text_elementandtomaketheinitialcallto
ShowAndGrowElement().
ShowAndGrowElement()iscalledevery50millisecondsandresetsthe
transformand
styleattributesonthetextelementtonewvalueseachtimeitiscalled.Attheendof
ShowAndGrowElement,thefunctiontellstheECMAScriptenginetocallitselfagainafter50moremilliseconds.
'g'元素平移坐标系使得将原点移到视区的左下角.它也定义了当绘制文本字符串时所使用的填充颜色和字体尺寸.The'g'elementshiftsthecoordinatesystemsothattheoriginisshiftedtowardthelower-leftoftheviewingarea.Italsodefinesthefillcolorandfont-sizetousewhendrawingthetextstring.
'text'元素包含文本字符串并且是其性质在动画期间发生变化的那个元素.The'text'elementcontainsthetextstringandistheelementwhoseattributesgetchangedduringtheanimation.
如果脚本修改由精图的
orpropertiesthatarebeinganimatedbySVG's
animationelements,thescriptsmodifythebasevaluefortheanimation.Ifabasevalueismodifiedwhileananimationelementisanimatingthecorrespondingattributeorproperty,theanimationsarerequiredtoadjustdynamicallytothenewbasevalue.
如果脚本在
thesametimethatan
animationelementisanimatingthatproperty,theresultisimplementation-dependent;thus,itisrecommendedthatthisbeavoided.
19.4文档对象模型接口DOMinterfaces
ThefollowingtwointerfacesarefromSMILAnimation.Theyareincludedhereforeasyreference:
InterfaceElementTimeControl
TheElementTimeControlinterface,partoftheorg.w3c.dom.smilmoduleanddefinedinSMILAnimation:Supportedinterfaces,definescommonmethodsforelementswhichdefineanimationbehaviorscompatiblewithSMILAnimation.
Calling
beginElement()causestheanimationtobegininthesamewaythatananimationwithevent-basedbegintimingbegins.TheeffectivebegintimeisthecurrentpresentationtimeatthetimeoftheDOMmethodcall.Notethat
beginElement()issubjecttothe
restartattributeinthesamemannerthatevent-basedbegintimingis.Ifananimationisspecifiedtodisallowrestartingatagivenpoint,
beginElement()methodscallsmustfail.Referalsotothesection
Restartinganimation.
Calling
beginElementAt(seconds)hasthesamebehavioras
beginElement(),exceptthattheeffectivebegintimeisoffsetfromthecurrentpresentationtimebyanamountspecifiedasaparameter.Passinganegativevaluefortheoffset
causestheelementtobeginasfor
beginElement(),buthastheeffectthattheelementbeginsatthespecifiedoffsetintoitsactiveduration.The
beginElementAt()methodmustalsorespectthe
restartattribute.Therestartsemanticsfora
beginElementAt()methodcallareevaluatedatthetimeofthemethodcall,andnotattheeffectivebegintimespecifiedbytheoffsetparameter.
Calling
endElement()causesananimationtoendtheactiveduration,justas
enddoes.Dependinguponthevalueofthe
fillattribute,theanimationeffectmaynolongerbeapplied,oritmaybefrozenatthecurrenteffect.Referalsotothesection
Freezinganimations.Ifananimationisnotcurrentlyactive(i.e.ifithasnotyetbegunorifitisfrozen),the
endElement()methodwillfail.
Calling
endElementAt()causesananimationtoendtheactiveduration,justas
endElement()does,butallowsthecallertospecifyapositiveoffset,tocausetheelementtoendatapointinthefuture.Otherthandelayingwhentheendactuallyhappens,thesemanticsareidenticaltothosefor
endElement().If
endElementAt()iscalledmorethanoncewhileanelementisactive,theendtimespecifiedbythelastmethodcallwilldeterminetheendbehavior.
IDLDefinition
interfaceElementTimeControl{
booleanbeginElement()
raises(DOMException);
booleanbeginElementAt(infloatoffset)
raises(DOMException);
booleanendElement()
raises(DOMException);
booleanendElementAt(infloatoffset)
raises(DOMException);
};
MethodsbeginElement
Causesthiselementtobeginthelocaltimeline(subjecttorestartconstraints).
NoParameters
Returnvalue
boolean | trueifthemethodcallwassuccessfulandtheelementwasbegun. falseifthemethodcallfailed.Possiblereasonsforfailureinclude: Theelementisalreadyactiveandcannotberestartedwhenitisactive.The restartattributeissetto "whenNotActive". Theelementisactiveorhasbeenactiveandcannotberestarted.The restartattributeissetto "never". |
DOMException | SYNTAX_ERR:TheelementwasnotdefinedwiththeappropriatesyntaxtoallowbeginElementcalls. |
Causesthiselementtobeginthelocaltimeline(subjecttorestartconstraints),atthepassedoffsetfromthecurrenttimewhenthemethodiscalled.Iftheoffsetis>=0,thesemanticsareequivalenttoanevent-basebeginwiththespecifiedoffset.If
theoffsetis<0,thesemanticsareequivalenttobeginElement(),buttheelementactivedurationisevaluatedasthoughtheelementhadbegunatthepassed(negative)offsetfromthecurrenttimewhenthemethodiscalled.
Parameters
infloatoffset | Theoffsetinsecondsatwhichtobegintheelement. |
boolean | trueifthemethodcallwassuccessfulandtheelementwasbegun. falseifthemethodcallfailed.Possiblereasonsforfailureinclude: Theelementisalreadyactiveandcannotberestartedwhenitisactive.The restartattributeissetto "whenNotActive". Theelementisactiveorhasbeenactiveandcannotberestarted.The restartattributeissetto "never". |
DOMException | SYNTAX_ERR:TheelementwasnotdefinedwiththeappropriatesyntaxtoallowbeginElementAtcalls. |
Causesthiselementtoendthelocaltimeline.
NoParameters
Returnvalue
boolean | trueifthemethodcallwassuccessfulandtheelementwasended. falseifmethodcallfailed.Possiblereasonsforfailureinclude: Theelementisnotactive. |
DOMException | SYNTAX_ERR:TheelementwasnotdefinedwiththeappropriatesyntaxtoallowendElementcalls. |
Causesthiselementtoendthelocaltimelineatthespecifiedoffsetfromthecurrenttimewhenthemethodiscalled.
Parameters
infloatoffset | Theoffsetinsecondsatwhichtoendtheelement.Mustbe>=0. |
boolean | trueifthemethodcallwassuccessfulandtheelementwasended. falseifthemethodcallfailed.Possiblereasonsforfailureinclude: Theelementisnotactive. |
DOMException | SYNTAX_ERR:TheelementwasnotdefinedwiththeappropriatesyntaxtoallowendElementAtcalls. |
packageorg.w3c.dom.svg;
importorg.w3c.dom.DOMException;
publicinterfaceElementTimeControl{
booleanbeginElement()
throwsDOMException;
booleanbeginElementAt(floatoffset)
throwsDOMException;
booleanendElement()
throwsDOMException;
booleanendElementAt(floatoffset)
throwsDOMException;
}
InterfaceTimeEvent
TheTimeEventinterface,definedinSMILAnimation:Supportedinterfacesdefinedin
SMILAnimation:Supportedinterfaces,providesspecificcontextualinformationassociatedwithTimeevents.
Thedifferenttypesofeventsthatcanoccurare:
beginEvent
Thiseventisraisedwhentheelementlocaltimelinebeginstoplay.Itwillberaisedeachtimetheelementbeginstheactiveduration(i.e.whenitrestarts,butnotwhenitrepeats).Itmayberaisedbothinthecourseofnormal(i.e.scheduledorinteractive)
timelineplay,aswellasinthecasethattheelementwasbegunwiththe
beginElement()or
beginElementAt()methods.Notethatifanelementisrestartedwhileitiscurrentlyplaying,theelementwillraiseanendeventandanotherbeginevent,astheelementrestarts.
·Bubbles:No
·Cancelable:No
·ContextInfo:None
endEvent
Thiseventisraisedattheactiveendoftheelement.Notethatthiseventisnotraisedatthesimpleendofeachrepeat.Thiseventmayberaisedbothinthecourseofnormal(i.e.scheduledorinteractive)timelineplay,aswellasinthecasethattheelement
wasendedwiththe
endElement()or
endElementAt()methods.Notethatifanelementisrestartedwhileitiscurrentlyplaying,theelementwillraiseanendeventandanotherbeginevent,astheelementrestarts.
·Bubbles:No
·Cancelable:No
·ContextInfo:None
repeatEvent
Thiseventisraisedwhenanelementlocaltimelinerepeats.Itwillberaisedeachtimetheelementrepeats,afterthefirstiteration.
Theeventprovidesanumericalindicationofwhichrepeatiterationisbeginning.Thevalueisa0-basedinteger,buttherepeateventisnotraisedforthefirstiterationandsotheobservedvaluesofthedetailattributewillbe>=1.
·Bubbles:No
·Cancelable:No
·ContextInfo:detail(currentiteration)
IDLDefinition
interfaceTimeEvent:events::Event{
readonlyattributeviews::AbstractViewview;
readonlyattributelongdetail;
voidinitTimeEvent(inDOMStringtypeArg,inviews::AbstractViewviewArg,inlongdetailArg);
};
Attributes
readonlyviews::AbstractViewview
The
viewattributeidentifiestheAbstractView[
readonlylongdetail
SpecifiessomedetailinformationabouttheEvent,dependingonthetypeoftheevent.Forthiseventtype,indicatestherepeatnumberfortheanimation.
Methods
initTimeEvent
TheinitTimeEventmethodisusedtoinitializethevalueofaTimeEventcreatedthroughthe
DocumentEventinterface.ThismethodmayonlybecalledbeforetheTimeEventhasbeendispatchedviathe
dispatchEventmethod,thoughitmaybecalledmultipletimesduringthatphaseifnecessary.Ifcalledmultipletimes,thefinalinvocationtakesprecedence.
Parameters
inDOMStringtypeArg | Specifiestheeventtype. | |
inviews::AbstractViewviewArg | SpecifiestheEvent'sAbstractView. | |
inlongdetailArg | SpecifiestheEvent'sdetail. |
NoExceptions
ThecorrespondingJavabinding:
packageorg.w3c.dom.svg;
importorg.w3c.dom.events.Event;
importorg.w3c.dom.views.AbstractView;
publicinterfaceTimeEventextends
Event{
publicAbstractViewgetView();
publicintgetDetail();
voidinitTimeEvent(StringtypeArg,AbstractViewviewArg,intdetailArg);
}
Thefollowinginterfacesaredefinedbelow:
SVGAnimationElement,
SVGAnimateElement,
SVGSetElement,
SVGAnimateMotionElement,
SVGMPathElement,
SVGAnimateColorElement,
SVGAnimateTransformElement.
InterfaceSVGAnimationElement
TheSVGAnimationElementinterfaceisthebaseinterfaceforalloftheanimationelementinterfaces:SVGAnimateElement,
SVGAnimateTransformElement.
UnlikeotherSVGDOMinterfaces,theSVGDOMdoesnotspecifyconvenienceDOMpropertiescorrespondingtothevariouslanguageattributesonSVG'sanimationelements.Specificationoftheseconveniencepropertiesinawaythatwillbecompatiblewithfuture
versionsofSMILAnimationisexpectedinafutureversionofSVG.Thecurrentmethodforaccessingandmodifyingtheattributesontheanimationelementsistousethestandard
getAttribute,
setAttribute,
getAttributeNSand
setAttributeNSdefinedinDOM2.
IDLDefinition
interfaceSVGAnimationElement:
SVGElement,
SVGTests,
SVGExternalResourcesRequired,
smil::ElementTimeControl,
events::EventTarget{
readonlyattributeSVGElementtargetElement;
floatgetStartTime();
floatgetCurrentTime();
floatgetSimpleDuration()
raises(DOMException);
};
Attributes
readonlySVGElementtargetElement
Theelementwhichisbeinganimated.
Methods
getStartTime
Returnsthestarttimeinsecondsforthisanimation.
NoParameters
Returnvalue
float | Thestarttimeinsecondsforthisanimationrelativetothestarttimeofthetimecontainer. |
getCurrentTime
Returnsthecurrenttimeinsecondsrelativetotimezeroforthegiventimecontainer.
NoParameters
Returnvalue
float | Thecurrenttimeinsecondsrelativetotimezeroforthegiventimecontainer. |
getSimpleDuration
Returnsthenumberofsecondsforthesimpledurationforthisanimation.Ifthesimpledurationisundefined(e.g.,theendtimeisindefinite),thenanexceptionisraised.
NoParameters
Returnvalue
float | Thenumberofsecondsforthesimpledurationforthisanimation. |
DOMException | NOT_SUPPORTED_ERR:Thesimpledurationisnotdeterminedonthegivenelement. |
InterfaceSVGAnimateElement
TheSVGAnimateElementinterfacecorrespondstothe'animate'element.Object-orientedaccesstotheattributesofthe'animate'elementviatheSVGDOMisnotavailable.
IDLDefinition
interfaceSVGAnimateElement:SVGAnimationElement{};
InterfaceSVGSetElement
TheSVGSetElementinterfacecorrespondstothe'set'element.Object-orientedaccesstotheattributesofthe'set'elementviatheSVGDOMisnotavailable.
IDLDefinition
interfaceSVGSetElement:SVGAnimationElement{};
InterfaceSVGAnimateMotionElement
TheSVGAnimateMotionElementinterfacecorrespondstothe'animateMotion'element.Object-orientedaccesstotheattributesofthe'animateMotion'elementviatheSVGDOMisnotavailable.
IDLDefinition
interfaceSVGAnimateMotionElement:SVGAnimationElement{};
InterfaceSVGMPathElement
TheSVGMPathElementinterfacecorrespondstothe'mpath'element.IDLDefinition
interfaceSVGMPathElement:
SVGElement,
SVGURIReference,
SVGExternalResourcesRequired{};
InterfaceSVGAnimateColorElement
TheSVGAnimateColorElementinterfacecorrespondstothe'animateColor'element.Object-orientedaccesstotheattributesofthe'animateColor'elementviatheSVGDOMisnotavailable.
IDLDefinition
interfaceSVGAnimateColorElement:SVGAnimationElement{};
InterfaceSVGAnimateTransformElement
TheSVGAnimateTransformElementinterfacecorrespondstothe'animateTransform'element.Object-orientedaccesstotheattributesofthe'animateTransform'elementviatheSVGDOMisnotavailable.
IDLDefinition
interfaceSVGAnimateTransformElement:SVGAnimationElement{};
next
contents
elements
attributes
properties
index
相关文章推荐
- Android的Animation动画相继
- AJ学IOS(40)UI之核心动画_抖动效果_CAKeyframeAnimation
- Animation(动画)
- Android动画学习笔记-Android Animation
- Android Animation动画(很详细)
- QML中的RotationAnimation旋转动画
- 动画效果编程基础--AnimationAndroid
- android 动画属性(一)之Animation
- 深入理解CSS3 Animation 帧动画(step详解)
- webkit-animation css3 动画
- Android Tween动画之RotateAnimation实现图片不停旋转效果实例介绍
- Android 动画之 ---- Drawable Animation (Frame动画,帧动画)
- 动画缓冲或叫缓动函数(Animation Easing)
- Android开发学习之Animation之Android帧动画解析
- Expression Blend实例中文教程(7) - 动画基础快速入门Animation
- Silverlight & Blend动画设计系列九:动画(Animation)与视图状态管理(Visual State Manager)
- 构造自己的动画函数:animation,stop功能的实现
- Android:关于Animation的几种常见的动画
- LayoutAnimationController,补间动画,属性动画,值动画,自定义动画,帧动画
- 指定FPS帧频,requestAnimationFrame播放动画