在raphael中如何根据返回的图片动态设置图片大小比例?
这里有一些代码可以给你一个想法:
var viewer = Raphael(0,0,scrWidth, scrHeight);
viewer.image(dynamicUrl, 140, 140,300, scaledHeight);
谢谢
最佳答案
您可以在 DOM 外部加载图像并获取其尺寸...您可以将其放入函数中:
var myImg = new Image();
myImg.src = dynamicUrl;
myImg.onload = function() {
var width = myImg.width;
var height = myImg.height;
var scale = 0.5; // for example
var viewer = Raphael(0,0,width, height); // or whatever other size
viewer.image(dynamicUrl, 0, 0, width*scale, height*scale); // scale image
// after the image is in the viewer you can use .scale()
}
现在您可以将 width
和 height
相除或相乘以进行缩放。请务必注意时间安排。
此外,一旦图像在 Raphael 中,您就可以使用 .scale()
关于javascript - 如何根据 raphael 中返回的图像动态设置图像大小比例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3976130/