找回密码
 立即注册
相关推荐换一批
  1. GB 2858.1-1981 冷冲模模板 矩形凹模板
  2. YD/T 910.3-1997 900/1800MHz TDMA数字蜂窝移动通信网移动业务交换中心与基站子系统
  3. YD/T 855.3-1996 900MHzDMA数字蜂窝移动通信网移动业务交换中心与基站子系统间接上
  4. YD/T 1050-2000 800MHzCDMA数字蜂窝移动通信网设备总测试规范:移动台部分
  5. YD/T 1030-1999 800MHz CDMA数字蜂窝移动通信网接口技术要求:空中接口
  6. YD/T 1025-1999 900/1800MHz TDMA数字蜂窝移动通信网移动台人机接口和SIM-ME接口技?
  7. YD/T 1038-2000 900/1800MHzTDMA数字蜂窝移动通信网移动应用部分(phase2 )技术规范
  8. YB/T 001-1991 初轧坯尺寸、外形、重量及允许偏差
  9. JB/T 5110.5-1992 螺旋压力机锻模 矩形模块用模座
  10. YD/T 1396-2005 900/18000MHz TDMA数字蜂窝移动通信网位置业务设备技术要求:服务移?
  11. GB/T 4678.3-1984 压铸模零件 矩形镶块
  12. GB/T 5160-1985 金属粉末 用矩形压坯的横向断裂测定压坯强度的方法
  13. SJ 2516-1984 矩形60°H面切角弯波导组件
  14. SJ 2345-1983 矩形圆弧扭波导组件
  15. SJ 2337-1983 矩形波导组件总技术条件
  16. SJ/T 10711-1996 移动通讯设备标准试验条件
  17. SJ/T 10519.13-1994 塑料注射模零件 矩形顶杆
  18. SJ/T 10502-1994 CD5型矩形连接器
  19. SJ/T 10341.29-1993 精冲模模板 矩形模板
  20. SJ/T 10291-1991 不锈钢波导法兰盘
  21. YD/T 1397-2005 900/1800MHz TDMA数字蜂窝移动通信网位置业务设备测试方法:服务移动
  22. GB/T 6092-1985 90°角尺
  23. GB/T 10959-1989 带移动工作台木工锯板机 精度
  24. GB/T 10919-1989 矩形花键量规
this矩形移动mouseMoveX | 软件设计/软件工程 2022-05-04 413 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字符串?