找回密码
 立即注册
相关推荐换一批
  1. YD/T 2674-2013 移动智能终端信息安全设计导则
  2. YD/T 1538-2014 代替 YD/T 1538-2011 数字移动终端 音频性能技术要求及测试方法
  3. YD/T 2502-2013 手机支付 移动终端安全技术要求
  4. YD/T 1607-2016 代替 YD/T 1607-2007 移动终端图像及视频传输特性技术要求和测试方法
  5. GB/T 29479.2-2020 移动实验室 第2部分:能力要求
  6. YD/T 3175-2016 800MHz/2GHz cdma2000 数字蜂窝移动通信网 (第二阶段) 设备技术要求
  7. HG/T 3187-2012 代替 HG/T 3187-1999 矩形块孔式石墨换热器
  8. GB/T 29471-2020 食品安全检测移动实验室通用技术规范
  9. GB/T 29473-2020 移动实验室分类、代号及标记
  10. DL/T 2031-2019 电力移动应用软件测试规范
  11. GB/T 37036.4-2021 信息技术 移动设备生物特征识别第4部分:虹膜
  12. DL/T 1511-2016 电力系统移动作业PDA终端安全防护技术规范
  13. GB/T 40028.2-2021 智慧城市 智慧医疗 第2部分:移动健康
  14. GB/T 40122-2021 全断面隧道掘进机 矩形土压平衡顶管机
  15. QX/T 83-2019 移动气象台建设规范
  16. GB/T 37036.2-2019 信息技术 移动设备生物特征识别 第2部分:指纹
  17. GB∕T 36524-2018 冲模 矩形截面压缩弹簧 安装尺寸和颜色标识
  18. GB/T 34201-2017 结构用方形和矩形热轧无缝钢管
  19. YB/T 2011-2014 连续铸钢方坯和矩形坯
  20. GB/T 31016-2014 移动实验室 样品采集与处理通用技术规范
  21. HG/T 3187-2012 矩形块孔式石墨换热器
  22. YD/T 1576.23-2013 800MHz2GHz cdma2000数字蜂窝移动通信网设备测试方法 移动台(含?
  23. YD/T 1576.22-2013 800MHz2GHz cdma2000数字蜂窝移动通信网设备测试方法 移动台(含?
  24. LY/T 1108-2013 矩形振动筛
this矩形移动mouseMoveX | 软件设计/软件工程 2022-05-04 372 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
问题
我想根据鼠标移动移动一个矩形。请参阅下面的链接。

在 mousedown 事件中获取矩形开始位置并开始拖动它将在鼠标移动事件中创建矩形。但是当我移动到上一个值时(即移动到小于鼠标向下按钮的值,它将返回一个负值),宽度变为负值。

上面的链接是画布矩形。但我用相同的逻辑创建了 svg 矩形。

不支持矩形的负宽度?或者如何根据鼠标移动移动矩形?

发生了什么?

我的代码片段。
  1. ChartMouseDown:function(e){

  2. //       e = this.normalizeMouseEvent(e);


  3.       var mousedownCords=this.calMousePosition(e);
  4.       this.mouseDownX=mousedownCords.X;
  5.       this.mouseDownY=mousedownCords.Y;

  6.       this.chartMouseDownPoint= this.GetValuebyPoint(Math.abs(this.mouseDownX-this.model.m_AreaBounds.X),Math.abs(this.mouseDownY-(this.model.m_AreaBounds.Y + this.model.m_AreaBounds.Height)));
  7.       this.zoomingX=true;

  8.     },



  9. ChartMouseMove: function (evt) {

  10.     if( this.zoomingX)
  11.     {

  12.     var mouseMoveX,mouseMoveY;

  13.      var mouseMoveCords=this.calMousePosition(evt);
  14.       mouseMoveX=mouseMoveCords.X;
  15.       mouseMoveY=mouseMoveCords.Y;
  16.       $(this.ZoomAreaRect).remove();
  17.       var width =  Math.abs(mouseMoveX - this.mouseDownX);
  18.       var height = mouseMoveY - this.mouseDownY;
  19.       var x;
  20.       if(mouseMoveX > this.mouseDownX)
  21.       x= this.mouseDownX;
  22.       else
  23.       x= mouseMoveX;

  24.        this.ZoomAreaRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");

  25.         $(this.ZoomAreaRect).attr({
  26.             'id': 'ZoomArea', 'x': x, 'y': this.model.m_AreaBounds.Y, 'width': width, 'height': this.model.m_AreaBounds.Height,
  27.             'fill': 'gray', 'stroke-width': 1, 'stroke':'gray'
  28.         });

  29.        $(this.ZoomAreaRect).appendTo(this.SvgObject);

  30.     }


  31. calMousePosition:function(e)
  32.     {
  33.      var matched = jQuery.uaMatch( navigator.userAgent );
  34.      var browser = {};
  35.      var mouseX,mouseY;
  36.      if(matched.browser.toLowerCase()=="mozilla")
  37.         {
  38.         mouseX = (e.pageX)-  $(this.SvgObject).parent().offset().left;
  39.         mouseY=  (e.pageY) - $(this.SvgObject).parent().offset().top;
  40.         }
  41.         else
  42.         {
  43.         mouseX =  (e.pageX +document.documentElement.scrollLeft)-$(this.SvgObject).offset().left;
  44.         mouseY =  (e.pageY + document.documentElement.scrollTop) - $(this.SvgObject).offset().top;
  45.         }

  46.         return { X: mouseX, Y:mouseY};

  47.     },
复制代码

谢谢,

湿婆

回答
如果您想在 SVG 中实现这一点,您必须确保矩形的宽度/高度始终为正并相应地计算 x/y。





上一篇:Dockerize 微服务未在 Eureka 服务器中注册
下一篇:Java中的字符序列VS字符串?