//鼠标坐标:在SVG经过缩放、偏移、ViewBox转换后,鼠标坐标值
var mouseCoord = {
x : .,
y : .
};
//用户坐标:相对于原始SVG,坐标位置
var userCoord = {
x : .,
y : .
};
var cRadius = .; //半径 var svgDocument = null;
var svgRoot = null; //获取鼠标事件相关的SVG Document
function getSVGDocument(evt)
{
var target = evt.target;
var parent = target.parentNode;
svgDocument = parent.getOwnerDocument();
svgRoot = svgDocument.documentElement;
} //计算坐标位置:包括用户坐标、鼠标坐标
function getCoords(evt)
{
var x_trans = .; //X偏移
var y_trans = .; //Y偏移
var x_scale = .; //ViewBox导致的X缩放比例
var y_scale = .; //ViewBox导致的Y缩放比例
var scale = .; //缩放比例
var trans = null;
var viewbox = null; getSVGDocument(evt); scale = svgRoot.currentScale; //获取当前缩放比例
trans = svgRoot.currentTranslate; //获取当前偏移
//获取SVG的当前viewBox
viewbox = svgRoot.getAttributeNS(null, "viewBox"); //获取ViewBox属性 //获取用户坐标:原始SVG的坐标位置
userCoord.x = evt.getClientX();
userCoord.y = evt.getClientY(); //计算偏移、缩放等
x_trans = ( 0.0 - trans.x ) / scale;
y_trans = ( 0.0 - trans.y ) / scale;
// Now that we have moved the rectangle's corner to the
// upper-left position, let's scale the rectangle to fit
// the current view. X and Y scales are maintained seperately
// to handle possible anamorphic scaling from the viewBox
zoom = scale;
x_scale = 1.0 / scale;
y_scale = 1.0 / scale;
if ( viewbox ) {
// We have a viewBox so, update our translation and scale
// to take the viewBox into account
// Break the viewBox parameters into an array to make life easier
var params = viewbox.split(//s+/);
// Determine the scaling from the viewBox
// Note that these calculations assume that the outermost
// SVG element has height and width attributes set to 100%.
var h_scale = 1.0 / parseFloat(params[]) * window.innerWidth;
var v_scale = 1.0 / parseFloat(params[]) * window.innerHeight;
// Update our previously calculated transform
x_trans = x_trans / h_scale + parseFloat(params[]);
y_trans = y_trans / v_scale + parseFloat(params[]);
x_scale = x_scale / h_scale;
y_scale = y_scale / v_scale;
}
//根据用户坐标、偏移量、缩放等计算鼠标坐标
mouseCoord.x = userCoord.x * x_scale + x_trans;
mouseCoord.y = userCoord.y * y_scale + y_trans;
}

在svg文间画图过程中放大缩小图片后,坐标偏移问题的更多相关文章

  1. 利用Gulp实现JSDoc 3的文档编写过程中的实时解析和效果预览

    ### 利用Gulp实现JSDoc 3的文档编写过程中的实时解析和效果预览 http://segmentfault.com/a/1190000002583569

  2. SAP 公司间STO场景中外向交货单过账后自动触发内向交货单功能的实现

    SAP 公司间STO场景中外向交货单过账后自动触发内向交货单功能的实现 如下STO,是从公司代码SZSP转入CSAS, 如下图示的内向交货单180018660.该内向交货单是在外向交货单8001632 ...

  3. 016 Android 图片选择器(在选中和未选中的过程中,切换展示图片)

    1.目标效果 在选中和未选中的过程中,切换展示图片 2.实现方法 (1)在app--->res--->drawable 右击drawable文件夹右键,new ---->drawab ...

  4. html 图片在一个div中放大缩小效果

    <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...

  5. Android 手势滑动,多点触摸放大缩小图片

    效果展示: 基本思路: <1>首先写一个图片控制类ImageControl,实现对图片控制的的基本操作,我们的图片控制类ImageControl是继承自ImageView自定义的视图: & ...

  6. Android多点触摸放大缩小图片

    1.Activity package com.fit.touchimage; import android.app.Activity; import android.graphics.Bitmap; ...

  7. ios 双指捏合放大缩小图片的例子

    图片跟随双指捏合的距离放大或者缩小. 利用-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event  实现. touchesMov ...

  8. svg查看预览 , 鼠标控制放大缩小 , 托拉拽等

    自己写是不可能了 , 所以要借用插件 svg-panzoom.js 地址 : https://github.com/ariutta/svg-pan-zoom#demos 及常见问题https://ww ...

  9. 关于asp.net中cookie在调试过程中读写正常发布后乱码问题

    最近在做的项目发布后出现了乱码的问题,既然出现了乱码很大的可能性是跟编码有关系,所以首先的解决方案就是重新对cookie进行编码, 在写入的cookie的时候编码,在读取的时候解码 在写入cookie ...

随机推荐

  1. Selenium系列(三) - 针对元素常见的简单操作

    如果你还想从头学起Selenium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1680176.html 其次,如果你不懂前端基础知识, ...

  2. MySQl数据类型和条件限制

    数据库的增删改查已经介绍完毕,今天从表的详细操作开始讲解 表操作 今日内容 1.数据类型 建表的时候,字段都有对应的数据类型 整型 浮点型 字符类型(char与varchar) 日期类型 枚举与集合 ...

  3. MySQL数据库02

    MySQL数据库 前言: 前面我们了解了什么是数据库,什么是MySQL数据库以及如何运用,接下来我们接着深入学习MySQL. (提前声明,以下所提供的事例不标准,仅供参考) 数据库的备份与还原: 备份 ...

  4. HDU-4252 A Famous City(单调栈)

    最后更新于2019.1.23 A Famous City ?戳这里可以前往原题 Problem Description After Mr. B arrived in Warsaw, he was sh ...

  5. HTTP 错误 500.21 模块 IIS Web Core

    如果出现如下图错误 就是iis没有安装Web Core模块 下载并安装DotNetCore.1.0.4_1.1.1-WindowsHosting.exe 安装完成之后会出现如下 证明安装成功.网站也可 ...

  6. Spring----注释----开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别

    来源:http://www.cnblogs.com/leiOOlei/p/3713989.html <context:annotation-config> 和 <context:co ...

  7. 使用一行Python代码从图像读取文本

    处理图像不是一项简单的任务.对你来说,作为一个人,很容易看着某样东西然后马上知道你在看什么.但电脑不是这样工作的. 对你来说太难的任务,比如复杂的算术,或者一般意义上的数学,是计算机毫不费力就能完成的 ...

  8. ||,&&短路规则测试

    短路规则:a||b中若a为真,则直接判断整个表达式为真,不再判断b是真或假,    a&&b中若a为假,则直接判断整个表达式为假,不再单独判断b是真或假. 想要测试这个规则的话,可以将 ...

  9. 前端验证,jquery.validate插件

    jQuery Validate 简介: jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用 ...

  10. python中如何在一个for循环中遍历两个列表

    `其实就是用zip把两个列表包装起来:  for x, y in zip(list1, list2)