raphael js,计算setViewBox宽高来固定窗口 [英] raphael js, calculate setViewBox width height to fix window

查看:43
本文介绍了raphael js,计算setViewBox宽高来固定窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一个宽度的 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?

感谢您的帮助:)

推荐答案

试试这个代码(你必须包含 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));

这篇关于raphael js,计算setViewBox宽高来固定窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆