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));
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfjbbg
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20