• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

raphael js,计算setViewBox宽高来固定窗口

用户头像
it1352
帮助1

问题说明

我的第一个宽度的 div 内容画布:1300,高度 = 500

My div content canvas in first width : 1300, height = 500

然后我将 div 调整为宽度 = 800,高度 = 500

Then I resize div to width = 800, height = 500

我将画布大小调整为宽度 = 800,高度 = 500 以修复窗口

And I resize canvas to width = 800, height = 500 to fix window

但是画布中的某些元素是隐藏的(因为我的画布宽度现在是 800 像素)

But Some Elements in canvas is hide (because My canvas width now is 800px)

所以我使用 setViewBox 来缩放它以固定宽度我的新宽度、高度

So I use setViewBox to zoom it to fix width my new width, height

结果:当我拖动它们时鼠标没有固定元素(我想我为 setViewBox 计算了错误的宽高)

Result: mouse not fix with element when I drag them (I think I calculate wrong width-height for setViewBox)

其他问题:有什么办法可以让向下拖动元素时画布高度自动延伸?

Other question: Have any way to let canvas height auto extend when drag element down?

感谢您的帮助:)

正确答案

#1

试试这个代码(你必须包含 jquery raphael js 2.x):

try this code (you have to include jquery raphael js 2.x) :

var original_width = 777;
var original_height = 667;
var zoom_width = map_width*100/original_width/100;
var zoom_height = map_height*100/original_height/100;
if(zoom_width<=zoom_height)
   zoom = zoom_width;
else
   zoom = zoom_height;
rsr.setViewBox($("#" map_name).offset().left, $("#" map_name).offset().top, (map_width/zoom), (map_height/zoom));

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfjbbg
系列文章
更多 icon
同类精品
更多 icon
继续加载