新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论SVG, GML, X3D, VRML, VML, XAML, AVALON, Batik等基于XML的图形技术,以及有关GIS的应用。
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - 高级XML应用『 SVG/GML/VRML/X3D/XAML 』 → svg简单动画的四种方法 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 6313 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: svg简单动画的四种方法 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 svg简单动画的四种方法

    1.SVG and SMIL

    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
        "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
    <svg xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink">
        <rect y="45" width="10" height="10" fill="red">
            <animate attributeName="x" from="0" to="90" dur="10s"
                     repeatCount="indefinite"/>
        </rect>
    </svg>

    实例演示:http://www.kevlindev.com/tutorials/basics/animation/svg_smil/horizontal.svg


    2.javascript and the DOM (using SMIL elements)

    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
        "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
        <!ATTLIST svg
                  xmlns:a3 CDATA #IMPLIED
                  a3:scriptImplementation CDATA #IMPLIED>
        <!ATTLIST script
                  a3:scriptImplementation CDATA #IMPLIED>
    ]>
    <svg onload="makeShape(evt)"
         xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
         a3:scriptImplementation="Adobe">
        <script type="text/ecmascript" a3:scriptImplementation="Adobe"><![CDATA[
            var svgns = "http://www.w3.org/2000/svg";
            function makeShape(evt) {
                var rect, animateX;
                if ( window.svgDocument == null )
                    svgDocument = evt.target.ownerDocument;
                
                rect = svgDocument.createElementNS(svgns, "rect");
                rect.setAttributeNS(null, "y", "45");
                rect.setAttributeNS(null, "width", "10");
                rect.setAttributeNS(null, "height", "10");
                rect.setAttributeNS(null, "fill", "green");
                
                animateX = svgDocument.createElementNS(svgns, "animate");
                animateX.setAttributeNS(null, "attributeName", "x");
                animateX.setAttributeNS(null, "from", "0");
                animateX.setAttributeNS(null, "to", "90");
                animateX.setAttributeNS(null, "dur", "10s");
                animateX.setAttributeNS(null, "repeatCount", "indefinite");
                
                rect.appendChild(animateX);
                svgDocument.documentElement.appendChild(rect);
            }
        ]]></script>
    </svg>

    实例演示:http://www.kevlindev.com/tutorials/basics/animation/js_dom_smil/horizontal_js_smil.svg

    3.javascript and the DOM (integer - does not match SMIL)

    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
        "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
        <!ATTLIST svg
                  xmlns:a3 CDATA #IMPLIED
                  a3:scriptImplementation CDATA #IMPLIED>
        <!ATTLIST script
                  a3:scriptImplementation CDATA #IMPLIED>
    ]>
    <svg onload="animate(evt)"
         xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
         a3:scriptImplementation="Adobe">
        <script type="text/ecmascript" a3:scriptImplementation="Adobe"><![CDATA[
            var rect;
            var x = 0;
            var speed = 60;
            function animate(evt) {
                if ( window.svgDocument == null )
                    svgDocument = evt.target.ownerDocument;
                rect = svgDocument.getElementById("rect");
                setTimeout("advance()", speed);
            }
            function advance() {
                if ( ++x > 90 ) x  = 0;
                rect.setAttributeNS(null, "x", x);
                setTimeout("advance()", speed);
            }
        ]]></script>
        <rect id="rect" y="45" width="10" height="10" fill="red"/>
    </svg>

    实例演示:http://www.kevlindev.com/tutorials/basics/animation/js_dom/horizontal_js.svg

    4.javascript and the DOM (parametric - matches SMIL)

    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
        "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
        <!ATTLIST svg
                  xmlns:a3 CDATA #IMPLIED
                  a3:scriptImplementation CDATA #IMPLIED>
        <!ATTLIST script
                  a3:scriptImplementation CDATA #IMPLIED>
    ]>
    <svg onload="animate(evt)"
         xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
         a3:scriptImplementation="Adobe">
        <script type="text/ecmascript" a3:scriptImplementation="Adobe"><![CDATA[
            var svgRoot;
            var rect;
            
            var from  = 0;
            var to    = 90;
            var diff  = to - from;
            var dur   = 10 * 1000; // in milliseconds
            var speed = 33;
            function animate(evt) {
                if ( window.svgDocument == null )
                    svgDocument = evt.target.ownerDocument;
                
                rect    = svgDocument.getElementById("rect");
                svgRoot = svgDocument.documentElement;
                
                advance();
            }
            function advance() {
                var elapsed = svgRoot.getCurrentTime() * 1000;
                var percent = elapsed % dur / dur;
                var x       = from + percent * diff;
                
                rect.setAttributeNS(null, "x", x);
                setTimeout("advance()", speed);
            }
        ]]></script>
        <rect id="rect" y="45" width="10" height="10" fill="red"/>
    </svg>


    实例演示:http://www.kevlindev.com/tutorials/basics/animation/js_parametric_dom/horizontal_js.svg


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/4/20 8:33:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/3 22:53:17

    本主题贴数1,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  svg简单动画的四种方法(5618字) - 卷积内核,2006年4月20日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    7,148.438ms