新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   >>中国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的拖动的操作? 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2910 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 怎样实现对svg的拖动的操作? 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     anshigang0720 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:0
      积分:55
      门派:XML.ORG.CN
      注册:2005/9/16

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给anshigang0720发送一个短消息 把anshigang0720加入好友 查看anshigang0720的个人资料 搜索anshigang0720在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看anshigang0720的博客楼主
    发贴心情 怎样实现对svg的拖动的操作?

    怎样实现对svg的拖动的操作?请各位高手帮帮忙!!

       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/9/19 17:11:00
     
     cuijie 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:12
      积分:105
      门派:XML.ORG.CN
      注册:2005/9/26

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给cuijie发送一个短消息 把cuijie加入好友 查看cuijie的个人资料 搜索cuijie在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看cuijie的博客2
    发贴心情 
    在鼠标事件里处理,在onmousedown开始处理,在onmousemove中改变目标坐标,在onmouseup结束处理
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/9/27 8:54:00
     
     dong_xuelin 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:11
      积分:102
      门派:XML.ORG.CN
      注册:2005/6/23

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给dong_xuelin发送一个短消息 把dong_xuelin加入好友 查看dong_xuelin的个人资料 搜索dong_xuelin在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看dong_xuelin的博客3
    发贴心情 研究一下这段代码吧!
    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN"
    "http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd">

    <svg xml:space="preserve" viewBox="0 0 1.8 1.8" width="600" height="450" onload="DoOnLoad( evt )"
     contentScriptType="text/ecmascript">
    <desc>Functional Key Spline graph created in SVG and Javascript</desc>

    <script><![CDATA[
     
     var dragger = null;
     var origTransform = "";
     var oldX;
     var oldY;
     var origX;
     var origY;
     var oldTranslateX;
     var oldTranslateY;

     function DoOnMouseOver(evt)
     {
      var onObject = evt.getTarget();
      if( onObject.getAttribute("id") == "pointOne" || onObject.getAttribute("id") == "pointTwo")
      {
      onObject.getStyle().setProperty("opacity", "0.5");
      }
     }
     function DoOnMouseOut(evt)
     {
      var onObject = evt.getTarget();
      if( onObject.getAttribute("id") == "pointOne" || onObject.getAttribute("id") == "pointTwo")
      {
      onObject.getStyle().setProperty("opacity", "0.3");
      }

     }
        
     function DoOnLoad(evt)
     {
      // useless leftovers
      var el = getSVGDocument(evt.getTarget()).getElementById("pointOne");
      el.getStyle().setProperty("fill", "black");
     }

     function DoOnMouseDown(evt)
     {

      var onObject = evt.getTarget();
      if( onObject.getAttribute("id") == "pointOne" || onObject.getAttribute("id") == "pointTwo")
      {
       dragger = onObject;
       oldX = Math.abs(dragger.getAttribute("cx")); // has to be abs'd so
       oldY = Math.abs(dragger.getAttribute("cy")); // it isn't a string(?)
       origX = evt.getClientX();
       origY = evt.getClientY();
       oldTranslateX = 0; // not used any more?
       oldTranslateY = 0;
      }
     }

     function DoOnMouseMove(evt)
     {
        if( dragger != null )
        {
      dragger.getStyle().setProperty("opacity", "0.75");

      // problem is here - initially drops to zero - also, it has
      // to be multiplied by 0.004 for the exact display resolution
      // - wanted replace oldTranslateX with oldX, but it adds as a string?
      var newX = Math.max(Math.min((oldX + (evt.getClientX() - origX) * 0.004),1),0);
      var newY = Math.max(Math.min((oldY + (evt.getClientY() - origY) *-0.004),1),0);
      var curve = getSVGDocument(evt.getTarget()).getElementById("kSpline");
      if( dragger.getAttribute("id") == "pointOne" )
      {
       var other = getSVGDocument(evt.getTarget()).getElementById("pointTwo");
       var cLine1 = getSVGDocument(evt.getTarget()).getElementById("cL1");
       var curX2 = other.getAttribute("cx");
       var curY2 = other.getAttribute("cy");
       var transformT = "keySplines=\"" +
         Math.round(newX*100)/100 + " " + Math.round(newY*100)/100 + "  " +
         Math.round(curX2*100)/100 + " " + Math.round(curY2*100)/100 + "\"";

       curve.setAttribute("d", "M0,0C" +
         newX + "," + newY + " " +
         curX2 + "," + curY2 + " 1,1");
       cLine1.setAttribute("x2", newX);
       cLine1.setAttribute("y2", newY);
      }
      else
      {
       var other = getSVGDocument(evt.getTarget()).getElementById("pointOne");
       var cLine2 = getSVGDocument(evt.getTarget()).getElementById("cL2");
       var curX1 = other.getAttribute("cx");
       var curY1 = other.getAttribute("cy");
       var transformT = "keySplines=\"" +
         Math.round(curX1*100)/100 + " " + Math.round(curY1*100)/100 + "  " +
         Math.round(newX*100)/100 + " " + Math.round(newY*100)/100 + "\"";

       curve.setAttribute("d", "M0,0C" +
         curX1 + "," + curY1 + " " +  
         newX + "," + newY + " 1,1");
       cLine2.setAttribute("x2", newX);
       cLine2.setAttribute("y2", newY);
      }

      var coordsText = getSVGDocument(evt.getTarget()).getElementById("coords");
      coordsText.getFirstChild().setData(transformT);
        
      dragger.setAttribute("cx", newX);
      dragger.setAttribute("cy", newY);

        }
     }
     function DoOnMouseUp(evt)
     {
      if( dragger != null )
      {
       dragger.getStyle().setProperty("opacity", "0.3");
       dragger = null;
       origTransform = ""
       oldX = 0;
       oldY = 0;
       origX = 0;
       origY = 0;
       oldTranslateX = 0;
       oldTranslateY = 0;
      }
     }
     function getSVGDocument(node)
     {
      // given any node of the tree, will obtain the SVGDocument node.
      // must be careful: a Document node's ownerDocument is null!
      if( node.getNodeType() != 9 )  // if not DOCUMENT_NODE
       return node.getOwnerDocument();
      else
       return node;
     }
    ]]></script>


    <defs>
       <line id="sLine" x1="0" y1="0" x2="1" y2="0"
     style="stroke:#BBB;stroke-width:0.01" />
       <g id="lSet1">
         <use xlink:href="#sLine" x="0" y="1.0" />
         <use xlink:href="#sLine" x="0" y="0.9" />
         <use xlink:href="#sLine" x="0" y="0.8" />
         <use xlink:href="#sLine" x="0" y="0.7" />
         <use xlink:href="#sLine" x="0" y="0.6" />
         <use xlink:href="#sLine" x="0" y="0.5" />
         <use xlink:href="#sLine" x="0" y="0.4" />
         <use xlink:href="#sLine" x="0" y="0.3" />
         <use xlink:href="#sLine" x="0" y="0.2" />
         <use xlink:href="#sLine" x="0" y="0.1" />
         <use xlink:href="#sLine" x="0" y="0.0" />
       </g>
    </defs>

    <g id="all" onmouseover="DoOnMouseOver( evt )" onmouseout="DoOnMouseOut( evt )" onmousedown="DoOnMouseDown( evt )" onmouseup="DoOnMouseUp( evt )" onmousemove="DoOnMouseMove( evt )">
    <rect id="bg" x="-0.3" y="0.05" width="2.6" height="1.75"
     style="fill:white" />
    <text x="0.15" y="0.2" style="fill:#348;stroke:none;font-size:0.15;">Key Splines graph tool</text>
    <text x="-0.1" y="0.4" style="fill:#444;stroke:none;font-size:0.054;">
     <tspan x="-0.25" y="0.5">  This SVG file</tspan>
     <tspan x="-0.25" y="0.56">demonstrates how</tspan>
     <tspan x="-0.25" y="0.62">the 'keySplines' </tspan>
     <tspan x="-0.25" y="0.68">setting works for key</tspan>
     <tspan x="-0.25" y="0.74">interpolation in SMIL</tspan>
     <tspan x="-0.25" y="0.8">based animation.</tspan>
     <tspan x="-0.25" y="0.86">  The handles can</tspan>
     <tspan x="-0.25" y="0.92">be manipulated by </tspan>
     <tspan x="-0.25" y="0.98">dragging them </tspan>
     <tspan x="-0.25" y="1.04">around.</tspan>
    </text>

    <g id="graph" transform="translate(0.4,1.4) scale(1,1)"
      style="fill:none; stroke:black; stroke-width:.01">
       <g id="grid" transform="scale(1,-1)">
           <use x="0" y="0" xlink:href="#lSet1" />
           <use x="0" y="-1" xlink:href="#lSet1" transform="rotate(90)" />
           <line id="cL1" x1="0" y1="0" x2="0.5" y2="0.1" style="stroke:#444;stroke-width:0.005;" />
           <line id="cL2" x1="1" y1="1" x2="0.5" y2="0.9" style="stroke:#444;stroke-width:0.005;" />

           <circle id="pointOne" cx="0.5" cy="0.1" r=".03" transform="translate(0 0)"
      style="fill:black;stroke:#F66;stroke-width:0.006;opacity:0.3;" />
           <circle id="pointTwo" cx="0.5" cy="0.9" r=".03" transform="translate(0 0)"
      style="fill:black;stroke:#F66;stroke-width:0.006;opacity:0.3;" />

           <path id="kSpline" x="0" y="0" d="M0,0 C0.5,0.1 0.5,0.9 1,1" style="stroke:red;" />
       </g>
       <g id="textGrp" transform="scale(1)">
         <text x="0" y="-1.05" style="fill:grey;stroke:none;font-size:0.1;">y</text>
         <text x="1.05" y="0" style="fill:grey;stroke:none;font-size:0.1;">x</text>

         <text x="-0.1" y="0.1" style="fill:grey;stroke:none;font-size:0.07;">0,0</text>
         <text x="1" y="-1.05" style="fill:grey;stroke:none;font-size:0.07;">1,1</text>
         <text id="explan" x="0.05" y="0.16"
      style="fill:#444;stroke:none; font-size:0.05;">(You can select and copy the text below)</text>
         <text id="coords" x="0.05" y="0.25"
      style="fill:black;stroke:none;font-size:0.07;">keySplines="0.5 0.1  0.5 0.9"</text>

         <text x="0.9" y="0.38" style="fill:#333;stroke:none;font-size:0.04;">Copyleft 2000 - Burning Pixel Productions</text>
       </g>
    </g>

    </g>
    </svg>

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/9/27 9:10: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/10 22:00:32

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

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    70.313ms